使用iOS 8中的新功能,如果您在应用程序中使用相机,它将要求访问相机的权限,然后当您尝试重新拍摄照片时,它会要求获得访问照片库的权限.下次启动应用程序时,我希望检查相机和照片库是否具有访问权限.

对于相机,我检查一下
if ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] == AVAuthorizationStatusDenied)
{
// do something
}
Run Code Online (Sandbox Code Playgroud)
我正在为照片库寻找类似的东西.
我已经使用Interface Builder为UILabel中的文本指定了一个大小为14的自定义字体'Helvetica'.
我正在多个地方重复使用相同的标签,但在某些地方我必须以粗体显示文本.
有什么方法我可以指定使现有字体加粗而不是再次创建整个UIFont吗?这就是我现在所做的:
myLabel.font = [UIFont fontWithName:@"Helvetica Neue" size:14];
Run Code Online (Sandbox Code Playgroud) 我们可以不转换NSMutableAttributedString成NSString?
我有两个NSMutableAttributedStrings,我将第二个字符串附加到1st,如下所示:
[string1 appendAttributedString:string2];
因为我必须在标签上显示string1:
self.label1.text = (NSString *)string1;
Run Code Online (Sandbox Code Playgroud)
我收到了"unrecognized selector sent to instance"错误.
我在这里做错了吗?这不是分配NSMutableAttributedString标签的文本属性的正确方法吗?
我正处于圈复杂度(CC)的学习阶段.对于练习,我正在计算2个例子的圈复杂度,并想确认我的答案是否正确......
参考维基百科,CC由以下地址给出M = E ? N + 2P:
请帮忙.

这里,E = 8,N = 9,P = 1.因此,M = 8-9 +(2×1)= 1.
例2:

这里E = 11,N = 10且P = 1.因此M = 10-11 +(2×1)= 1.
因此,对于两个例子,CC都是1.如果我的计算是正确的,请告诉我.
我有一个字符串,其中最后一个单词与整个字符串中的其他单词相比总是具有不同的颜色,例如:如果字符串颜色为黑色,则语句中的最后一个单词将为红色.我正在使用NSAttributed字符串,如下所示:
NSDictionary *attrDict = [NSDictionary dictionaryWithObject:[UIFont fontWithName:Arial size:16.0] forKey:NSFontAttributeName];
NSMutableAttributedString *AattrString = [[NSMutableAttributedString alloc] initWithString:@"This is a" attributes: attrDict];
Run Code Online (Sandbox Code Playgroud)
我会为最后一个单词制作类似的NSAttributedString,并用第一个字符串修改它.
问题:我想在字符串中添加颜色和字体.我已经使用字典处理字体了.但是我可以在同一个字典中添加颜色处理程序/代码,或者在NSAttributedString上使用"addAttribute:"是添加颜色或任何其他属性的唯一方法吗?
我知道这个问题在这里被多次询问和回答.但是我第一次处理这个问题,仍然无法在脑海中完美地实现它.下面是我的委托方法我实现了从传递数据的代码SecondViewController来FirstViewController.
FirstViewController.h
#import "SecondViewController.h"
@interface FirstViewController : UITableViewController<sampleDelegate>
@end
Run Code Online (Sandbox Code Playgroud)
FirstViewController.m
@interface FirstViewController ()
// Array in which I want to store the data I get back from SecondViewController.
@property (nonatomic, copy) NSArray *sampleData;
@end
@implementation FirstViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SecondViewController *controller = [[SecondViewController alloc] init];
[self.navigationController pushViewController:controller animated:YES];
}
@end
Run Code Online (Sandbox Code Playgroud)
SecondViewController.h
@protocol sampleDelegate <NSObject>
- (NSArray*)sendDataBackToFirstController;
@end
@interface SecondViewController : UITableViewController
@property (nonatomic, strong) id <sampleDelegate> sampleDelegateObject;
@end
Run Code Online (Sandbox Code Playgroud)
SecondViewController.m
@interface SecondViewController ()
@property …Run Code Online (Sandbox Code Playgroud) 我在UITableView中有一个有多行的部分.我希望得到该部分的最后一行或最后一个单元格,以便在其上添加披露指标.
我想用的一种方法是:
NSIndexPath *lastCellIndexPath = [NSIndexPath indexPathForItem:[self.tableView numberOfRowsInSection:2]-1 inSection:2];
Run Code Online (Sandbox Code Playgroud)
有没有其他最好的方法来获取节上最后一个单元格的单元格或索引路径?
我尝试使用Sourcetree将代码推送到github时出现以下错误:
Pushing to http://github.myOrg.com/my-repo/my-proj.git
2014-09-23 13:05:20.500 git-credential-sourcetree[6744:507] Error (internetKeychainItemForServer:withUsername:path:port:protocol:) - The specified item could not be found in the keychain.
remote: Permission to ion-my-repo/my-proj.git denied to my-user-id.
fatal: unable to access 'http://github.myOrg.com/my-repo/my-proj.git/': The requested URL returned error: 403
Run Code Online (Sandbox Code Playgroud)
当我点击推送时,sourcetree会要求我提供与我的帐户相关的密码:
Password required
For user my-user-id on host github.myOrg.com
Run Code Online (Sandbox Code Playgroud)
所以看起来sourcetree知道什么是我的用户ID,它只需要密码来访问我的github帐户.我能够使用sourcetree提取内容,它不会问我的凭据.我也能够推动这个项目,但最近我的系统管理员在我的mac上用钥匙链做了一些事情,从那以后我就无法在github上推送任何东西了.
有人之前遇到过这个问题吗?
我正在寻找ruby存储在mac上的路径?
我在我的mac上安装了macruby,我正在尝试查看它的安装位置.我想在我的ruby脚本中包含macruby的路径.当我做rvm列表时,我得到:
=> macruby-0.12 [ i686 ]
* ruby-1.9.3-p545 [ x86_64 ]
ruby-2.1.1 [ x86_64 ]
ruby-2.1.2 [ x86_64 ]
ruby-2.1.2-version [ x86_64 ]
Run Code Online (Sandbox Code Playgroud)
我#!/usr/local/bin/macruby在我的ruby脚本中使用,但看起来像macruby在该位置不存在.当我执行"whereis ruby"命令时,我会回来"/usr/bin/ruby",但是当我执行"whereis ruby-1.9.3-p545"或者"whereis macruby-0.12"什么也没得到时.
我如何找到所有这些红宝石版本所在的路径?
你好我是一个NSObject类的类:
ProductDetails *details = [[ProductDetails alloc] init];
details.name = @"Soap1";
details.color = @"Red";
details.quantity = 4;
Run Code Online (Sandbox Code Playgroud)
我想将"details"对象传递给字典.
我做到了,
NSDictionary *dict = [NSDictionary dictionaryWithObject:details forKey:@"details"];
Run Code Online (Sandbox Code Playgroud)
我将此dict传递给另一个执行JSONSerialization检查的方法:
if(![NSJSONSerialization isValidJSONObject:dict])
Run Code Online (Sandbox Code Playgroud)
我在这张支票上遇到了崩溃.我在这里做错了吗?我知道我得到的细节是一个JSON对象,我将它分配给我的ProductDetails类中的属性.
请帮我.我是Objective-C的菜鸟.
我现在试过:
NSError* error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:(NSData*)details options:kNilOptions error:&error];
Run Code Online (Sandbox Code Playgroud)
我需要的只是将细节转换为NSData的简单方法.
我注意到我的对象里面有一个数组可能就是为什么我尝试的所有方法都抛出异常.然而,由于这个问题变得越来越大,我已经开始了另一个问题线程,在那里我显示了我在对象中获取的数据 - /sf/ask/1335677311/
ios ×6
objective-c ×4
macos ×2
addattribute ×1
delegates ×1
fonts ×1
git ×1
ios6 ×1
ios8 ×1
keychain ×1
macruby ×1
nsdictionary ×1
nsindexpath ×1
nsstring ×1
protocols ×1
ruby ×1
uifont ×1
uilabel ×1
uitableview ×1