ios - performSelectorInBackground 上的 EXC_BAD_ACCESS

标签 ios objective-c performselector

我想在后台调用这个方法,

-(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/

相关文章:

ios - UIScrollView contentsize 在使用自动布局时重置为零

ios - UIWebView 和 Swift : Detect when a video starts playing

ios - 如何在@selector方法中将int作为参数传递

ios - 使用 drawRect : 设置 UIView backgroundColor

objective-c - 转换为 (id) 以调用 Objective-C 中的任意方法

ios - Retina iPad 上 iOS 7 中的 WebKit 中的框阴影传播错误

ios - 如何遮盖部分重叠的UIBezierPaths

ios - 将 JSON 元素作为 Sections Title 和 Cell title 放入 TableView

objective-c - 在 CocoaPods 项目中使用@import

iOS: perform performSelector using nsstring : performSelector 可能会导致泄漏,因为它的选择器是未知的