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];