需要讀取@selector,請幫忙看看
解析一個參數到 @selector,實現代碼如下:
- (void)viewDidLoad{
[super viewDidLoad];
NewsCell *cell = (NewsCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil){
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"NewsCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
NSString *string = @"image.png";
[self performSelectorInBackground:@selector(doSomeThing::) withObject:nil];
}
-(void) doSomeThing:(UITableViewCell *)newsCell imageName:(NSString *)imageName{
NSLog(@"newsCell: %@", newsCell);
NSLog(@"imageName: %@", imageName);
}
創建了新的UITableViewCell名為cell,是從其它nib文件中加載的,並創建了新字符串名為string
問題,如何將cell和string作為參數發送到 performSelectorInBackground 中的 @selector ?
NSDictionary *args=[NSDictionary dictionaryWithObjectsAndKeys:cell,@"cell",string,@"imageName",nil];
[self performSelectorInBackground:@selector(doSomeThingWrapper:) withObject:dict];
-(void)doSomeThingWrapper:(NSDictionary *)args {
[self doSomeThing:(NewsCell*)[args objectForKey:@"cell"] imageName:[args objectForKey:@"imageName"]];
}