处理表格视图的单元格内的图像和标签
问题描述:
我已经在表格视图的每个单元格中创建了标签和图像。如果点击图片,我希望标签数据引用该单元格。处理表格视图的单元格内的图像和标签
- (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);
}
,但如何让 感谢ü
答
似乎有你的代码错误几件事情,标签数据等,其中有你的cellForRowAtIndexPath获得“细胞”?话虽如此,要解决您的紧急问题,您可以在cellForRowAtIndexPath中为您的手机标签添加一个标签,例如phone.tag = 5;
然后在你的手势识别器里面加入UILabel *phone = (UILabel *)[cell viewWithTag:5];
。现在您可以参考该单元格中的标签。
我在每一行我有一个图像和标签。每行中的标签数据不同 – siva 2013-04-03 22:42:23
k我知道了,谢谢你的回复 – siva 2013-04-03 23:00:39