2012-07-24 86 views
0

我的場景,在其中我在TableViewCell使用選擇的波紋管,當我在我看來,單擊後退按鈕我要取消選擇,我在選擇發送詞典作爲對象取消選擇在UITableViewCell中

我的代碼波紋管

在頭文件

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 [email protected]"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"]]]; 
    } 
} 

現在我想,當我按後退按鈕

取消此selecter並請記住,我已經使用

[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(DownloadImagesForCell:) object:dictImages]; 
+0

即使使用取消請求後,您是否選擇器被調用? – vishy 2012-07-24 06:46:32

+0

雅我認爲與我通過取消選擇器方法的對象的問題。 – iDhaval 2012-07-24 06:49:36

+0

'DownloadImagesForCell'在主UI線程的不同線程上工作,對吧?如果你已經從主線程調用'cancelPreviousPerformRequestsWithTarget',那麼我認爲它不會工作... – tipycalFlow 2012-07-24 07:12:47

回答