我有一个场景,其中我在TableViewCell中使用选择器如下所示,当我在视图中单击后退按钮时,我想取消该选择器,我将字典作为对象发送到选择器
我的代码如下:
在标题文件中
NSMutableDictionary* photoDict;
NSMutableDictionary* dictImages;
在.M文件中
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell==nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
[[NSBundle mainBundle]loadNibNamed:@"MyCellNib" owner:self options:Nil];
cell = detailChainObj;
}
NSString* avatarURL =@"image_Url"; //Any url of image for cell.
NSString *key =[[NSString alloc] initWithFormat:@"Key%d%d",indexPath.section,indexPath.row];
dictImages = [NSDictionary dictionaryWithObjectsAndKeys:imageViewCell,@"Img",imgURL,@"imgURL",key,@"key", nil];
[self performSelectorInBackground:@selector(DownloadLinkzImageOfUser:) withObject:dictImages];
if([photoDic valueForKey:keyAvt])
{
NSData* data = (NSData*)[photoDic valueForKey:key];
imageViewCell.image = [UIImage imageWithData:data];
}
else
{
[self performSelectorInBackground:@selector(DownloadImagesForCell:) withObject:dictImages];
}
}
//
-(void)DownloadImagesForCell:(NSDictionary *)result
{
UIImageView* img = (UIImageView*)[result objectForKey:@"Img"];
NSString* urlAvt = [result valueForKey:@"imgURL"];
if([urlAvt isEqualToString:@"No Image"])
{
img.image = [UIImage imageNamed:@"noimg.png"];
}
else
{
NSData* data = [NSData dataWithContentsOfURL:[NSURL URLWithString:imgURL]];
img.image = [UIImage imageWithData:data];
[photoDic setValue:data forKey:[NSString stringWithFormat:@"%@",[result valueForKey:@"key"]]];
}
}
现在我想在按下按钮
时取消此选择器请记住我已经使用
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(DownloadImagesForCell:) object:dictImages];
答案 0 :(得分:1)
我猜这个方法适用于performSelector:withObject:afterDelay:only。