我想在后台调用此方法,
-(void)downloadImage_3:(NSString* )Path AtIndex:(int)i
我以这种方式打电话,但它崩溃并显示
EXC_BAD_ACCESS
[self performSelectorInBackground:@selector(downloadImage_3:AtIndex:) withObject:[NSArray arrayWithObjects:@"http://www.google.com",i, nil]];
如何在后台调用
downloadImage_3:
方法?我在哪里做错了?
最佳答案
尝试这个
[self performSelectorInBackground:@selector(downloadImage_3:AtIndex:) withObject:[NSArray arrayWithObjects:@"http://www.google.com",i, nil] afterDelay:15.0];
或者试试这个
NSString* number = [NSString stringWithFormat:@"%d",i];
NSArray* arrayValues = [[NSArray alloc] initWithObjects:[[msg_array objectAtIndex:i] valueForKey:@"Merchant_SmallImage"],number, nil];
NSArray* arrayKeys = [[NSArray alloc] initWithObjects:@"Path",@"Index",nil];
NSDictionary* dic = [[NSDictionary alloc] initWithObjects:arrayValues forKeys:arrayKeys];
[self performSelectorInBackground:@selector(downloadImage_3:) withObject:dic];
定义downloadImage_3函数,如下所示:
-(void)downloadImage_3:(NSDictionary *)dic
{
NSString *path = [dic valueForKey:@"Path"];
int i = [[dic valueForKey:@"Index"] intValue];
//Your code
}
关于ios - 在performSelectorInBackground上为EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19853892/