我有这样的场景,我在 TableViewCell 中使用选择器,如下所示,当我单击视图中的后退按钮时,我想取消该选择器,并将字典作为对象发送到 Selector
我的代码如下
在头文件中
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];