您好,我上传后将图片从设备上传到服务器后必须返回主视图控制器,但我在应用中遇到了一些问题。上传图片后,我的应用程序崩溃了。
NSString *urlString = @"url";
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc]init]autorelease];
[request setURL:[NSURL URLWithString:urlString]] ;
[request setHTTPMethod:@"POST"];
NSString *boundary = @"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField:@"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary]dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Disposition: form-data; name=\"userfile\"; filename=\".jpg\"\r\n"dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: application/octet-stream\r\n\r\n"dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imageData]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary]dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"%@data",returnString);
[self temp];
[self performSelector:@selector(myMethod) withObject:nil afterDelay:3.0f];
alertTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(showAlert) userInfo:nil repeats:NO];
**[self performSelector:@selector(dissMissViewController) withObject:self afterDelay:4.0f];**
驳回守则。
- (void)dissMissViewController
{
[self dismissViewControllerAnimated:YES completion:^{
[self.navigationController popToRootViewControllerAnimated:YES];}];
}
我不在哪里我做错了请告诉我如何解决它。
感谢。
答案 0 :(得分:1)
没有堆栈跟踪很难解决它,但似乎是当你的目标被释放时调用你的showAlert方法。
你正在调用[self dismissModalViewController:],然后才调用 - showAlert。
如果VC没有保留在某个地方,你会在这里崩溃。
答案 1 :(得分:0)
如果您application
使用Navigation Controller
,那么
- (void)dissMissViewController {
[self.navigationController popViewControllerAnimated:YES];
}
否则,如果它不使用Navigation Controller
- (void)dissMissViewController {
[self dismissViewControllerAnimated:YES completion:nil];
}
答案 2 :(得分:0)
嗨感谢您的重播我通过更改警报视图中的时间间隔来解决问题,现在它正在工作f9。这是代码。
[self performSelector:@selector(myMethod) withObject:nil afterDelay:3.0f];
[self performSelector:@selector(dissMissViewController) withObject:self afterDelay:4.0f];
alertTimer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(showAlert) userInfo:nil repeats:NO];