我使用iOS 7的新NSURLSessionDataTask功能检索数据如下:
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:
request completionHandler:
^(NSData *data, NSURLResponse *response, NSError *error) {
//
}];
Run Code Online (Sandbox Code Playgroud)
如何增加超时值以避免错误"The request timed out"(在 NSURLErrorDomainCode =中-1001)?
我已经检查了NSURLSessionConfiguration的文档,但没有找到设置超时值的方法.
谢谢您的帮助!
当用户通过 Google 和 Facebook 身份提供商使用相同的电子邮件地址登录时,AWS Cognito 在用户池中创建多个条目,每个身份提供商使用一个条目:
我使用本教程中提供的示例代码来设置 AWS Cognito:使用 Amplify 框架进行用户身份验证的完整指南
amazon-web-services google-login amazon-cognito aws-lambda amazon-cognito-facebook
我使用类似于以下代码的基于块的枚举:
[[[rows objectForKey:self.company.coaTypeCode] objectForKey:statementType]
enumerateObjectsWithOptions:NSEnumerationConcurrent
usingBlock:^(id coaItem, NSUInteger idx, BOOL *stop) {
// block code here
}]
Run Code Online (Sandbox Code Playgroud)
我想在枚举过程中删除一些对象,具体取决于它们的对象值.
我怎么能这样做?我知道在枚举期间操纵可变数组或字典(NSMutableArray或NSMutableDictionary)通常是不可能的.
实现这个的最佳方法是什么?
谢谢!
objective-c nsmutablearray nsmutabledictionary ios objective-c-blocks
我使用iOS7的新URL请求方法获取数据,如下所示:
NSMutableURLRequest *request = [NSMutableURLRequest
requestWithURL:[NSURL URLWithString:[self.baseUrl
stringByAppendingString:path]]];
NSURLSessionDataTask *dataTask = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
NSUInteger responseStatusCode = [httpResponse statusCode];
if (responseStatusCode != 200) {
// RETRY (??????)
} else
completionBlock(results[@"result"][symbol]);
}];
[dataTask resume];
Run Code Online (Sandbox Code Playgroud)
不幸的是,我不时收到HTTP响应,表明服务器无法访问(response code != 200)并需要向服务器重新发送相同的请求.
如何才能做到这一点?我如何完成上面评论所在的代码片段// RETRY?
在我的示例中,我在成功获取后调用完成块.但是如何再次发送相同的请求呢?
谢谢!
我想设计一个UIView,它比Storyboard(iOS 5)中的ViewController大.
UIView应该用作UIScrollView的子视图,因此比我现有的任何ViewControllers都要大.如何在Storyboard中创建这样的UIView并将其与我的UIScrollView相关联?
如果可能的话,我想在没有xib文件的情况下这样做.
谢谢!
我有一个股票价格列表与属性dateTime和value.
目前,我在使用排序描述符获取股票价格时对其进行排序.
现在,我想更改我的代码并将其存储在已排序的顺序中,以便更快地检索最新的股价(dateTime = max).
我正在逐个插入股价
SharePrice *priceItem= [NSEntityDescription insertNewObjectForEntityForName:@"SharePrice" inManagedObjectContext:context];
如何在使用排序描述符插入后立即对股价进行排序dateTime?
或者我需要将其转换为NSMutableOrderedSet和使用sortUsingComparator:?
谢谢!
将右侧导航栏按钮设置为禁用时,它不会更改其颜色以向用户发出其禁用状态信号.
它仍然是"突出显示的",不是灰色的.
我在Storyboard中设置了按钮,如下所示:

self.navigationController.navigationItem.rightBarButtonItem.enabled = NO;
Run Code Online (Sandbox Code Playgroud)
我还需要做些什么来直观地改变按钮状态?
谢谢!
objective-c uikit uinavigationcontroller uibarbuttonitem ios
我经常需要将表视图单元格设置为初始选择状态,我使用以下代码:
[self.tableView selectRowAtIndexPath:indexPath
animated:NO scrollPosition:UITableViewScrollPositionNone];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
[cell setSelected:YES];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
Run Code Online (Sandbox Code Playgroud)
我正在使用selectRowAtIndexPath:indexPath并且setSelected:YES同时,因为我不完全理解这两种方式中的哪一种是以编程方式选择单元格的首选方式.
我应该使用哪一个陈述?为什么?
我使用以下NSCalendar方法获取日历年中的天数:
NSRange range = [gregorian rangeOfUnit:NSDayCalendarUnit
inUnit:NSYearCalendarUnit
forDate:date];
Run Code Online (Sandbox Code Playgroud)
我期望range.length返回值类型NSRange为365或366(天).
但是,此代码返回range.length的31对的日期值2005-06-06.
我的代码出了什么问题?
这是完整的代码段:
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
[subArray enumerateObjectsUsingBlock:
^(NSDate *date, NSUInteger idx, BOOL *stop) {
NSUInteger numberOfDays = [gregorian ordinalityOfUnit:NSDayCalendarUnit
inUnit:NSYearCalendarUnit forDate:date];
}];
Run Code Online (Sandbox Code Playgroud) 重命名我的项目文件夹后,我收到以下错误消息:
Warning: no rule to process file '/Users/cs/Documents/Xcode/Prototype/Prototype/Settings.bundle'
of type wrapper.plug-in for architecture i386
Warning: no rule to process file '/Users/cs/Documents/Xcode/Prototype/Prototype/DDMathParser/DDMathParser.h'
of type sourcecode.c.h for architecture i386
Warning: no rule to process file '/Users/cs/Documents/Xcode/Prototype/Prototype/AFNetworking/AFURLConnectionOperation.h'
of type sourcecode.c.h for architecture i386
Directory not found for option '-L"/Users/cs/Documents/Xcode/Prototype/Prototype/../../../FacebookSDK/FacebookSDK.framework"
Run Code Online (Sandbox Code Playgroud)
什么可能出错?
objective-c ×9
ios ×7
cocoa ×2
cocoa-touch ×2
ios5 ×2
aws-lambda ×1
core-data ×1
google-login ×1
http ×1
nscalendar ×1
nsdate ×1
nsset ×1
nsurlrequest ×1
swift ×1
uikit ×1
uiscrollview ×1
uitableview ×1
uiview ×1
xcode ×1
xcode5 ×1