2013-04-03 65 views
0

我已經在表格視圖的每個單元格中創建了標籤和圖像。如果點擊圖片,我希望標籤數據引用該單元格。處理表格視圖的單元格內的圖像和標籤

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UILabel *phone=[[[UILabel alloc]initWithFrame:CGRectMake(10, 95, 320,15)]autorelease]; 

    phone.font=[UIFont boldSystemFontOfSize:12]; 
    [phone setTextAlignment:UITextAlignmentLeft]; 
    [phone setText:[d valueForKey:@"Phone"]]; 
    [cell addSubview:phone]; 

    myImageView.image = [UIImage imageNamed:@"call.png"]; 
    cell.imageView.image=myImageView.image; 
    cell.imageView.userInteractionEnabled=YES; 

    UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageSelectedInTable:)]; 

    [cell.imageView addGestureRecognizer:tapped]; 
    [tapped release]; 
} 

-(IBAction)imageSelectedInTable:(UITapGestureRecognizer*)gesture 
{ 
    NSLog(@"Selected an Image"); 

    UIImageView *imgView = (UIImageView *) [gesture view]; 
    UITableViewCell *cell = (UITableViewCell*)[[imgView superview]superview]; 
    NSIndexPath *tappedIndexPath = [self.tableView indexPathForCell:cell]; 
    NSLog(@"Image Tap %@", tappedIndexPath); 
} 

,但如何讓 感謝ü

回答

0

似乎有你的代碼錯誤幾件事情,標籤數據等,其中有你的cellForRowAtIndexPath獲得「細胞」?話雖如此,要解決您的緊急問題,您可以在cellForRowAtIndexPath中爲您的手機標籤添加一個標籤,例如phone.tag = 5;然後在你的手勢識別器裏面加入UILabel *phone = (UILabel *)[cell viewWithTag:5];。現在您可以參考該單元格中的標籤。

+0

我在每一行我有一個圖像和標籤。每行中的標籤數據不同 – siva 2013-04-03 22:42:23

+0

k我知道了,謝謝你的回覆 – siva 2013-04-03 23:00:39

相關問題