我正在使用ASIHTTPRequest库从我的iPhone应用程序中的服务器请求一些数据.但我无法弄清楚如何创建超时,以便如果服务器出现故障或iPhone没有互联网连接,应用程序不会崩溃.
提前致谢
编辑>>>
tt.Kilew你的代码不起作用......我发布了一些示例代码
NSURL *url = [NSURL URLWithString:@"A URL WITH A FORM"];
ASIFormDataRequest *requestPOST = [ASIFormDataRequest requestWithURL:url];
[requestPOST setPostValue:un forKey:@"username"];
[requestPOST setPostValue:pw forKey:@"password"];
[requestPOST setPostValue:@"Login" forKey:@"submit"];
[requestPOST start];
[requestPOST setTimeOutSeconds:10];
NSLog(@"Fail: %@", [requestPOST failWithError:ASIRequestTimedOutError]);
Run Code Online (Sandbox Code Playgroud) 我试图用来dismissModalViewController:Animated:解雇我的观点,但无论我尝试什么,它都不会解雇它.您可以看到我尝试hideSplash在底部的方法中释放视图.请,如果有人可以提供帮助,将不胜感激.我的代码发布在下面:
#import "SplashViewController.h"
@implementation SplashViewController
- (void) didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void) viewDidUnload {
}
- (void) dealloc {
[super dealloc];
}
-(void) showSplash {
modalViewController = [[UIViewController alloc] init];
modalViewController.view = modelView;
[self presentModalViewController:modalViewController animated:NO];
[activityIndicator startAnimating ];
//[self bigcalculation];
//[self performSelector:@selector(hideSplash) withObject:nil afterDelay:2.0];
}
- (void) viewDidAppear:(BOOL)animated {
NSLog(@"View Did Appear");
[self bigcalculation];
}
- (void) bigcalculation {
NSLog(@"Big Calc Start");
for (int i = 0; i <= 648230; i++) {
for …Run Code Online (Sandbox Code Playgroud) 我正在尝试在objective-c中对多维数组进行排序,我知道我可以使用下面的代码行对单维数组进行排序:
NSArray *sortedArray = [someArray sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
Run Code Online (Sandbox Code Playgroud)
我似乎无法弄清楚如何对2D数组进行排序,如下所示:
( ("SOME_URL", "SOME_STORY_TITLE", "SOME_CATEGORY"),
("SOME_URL", "SOME_STORY_TITLE", "SOME_CATEGORY"),
("SOME_URL", "SOME_STORY_TITLE", "SOME_CATEGORY") );
Run Code Online (Sandbox Code Playgroud)
如果有人可以提供我将通过SOME_CATEGORY对数组进行排序的代码,那对我来说将是非常有帮助的.
谢谢,
Zen_Silence