Uitableview 无法在didrowselect方法中获取图像/单元格标记号。。。!
Hi-am在带有标记的cellrow中使用2 UIImageView,通过填充数组中的图像(如第0行的图像,第1行的图像)和第1行的图像(第2行的图像,第3行的图像)来顺序显示每一行,依此类推 我成功地为每个图像显示了带有适当标记的图像,但在didrowselect方法中未能获得图像或单元格的标记…我需要标记号直接将标记号作为数组索引传递给detailsegue…我对IOS编程不熟悉,我想知道我在这里是否做错了什么,请建议一种获得适当标签号的方法…非常感谢您在这方面的帮助,因为我只知道这项任务将要完成 粘贴我的代码供您参考:self.tagnumber=0;此代码用于显示偶数个图像Uitableview 无法在didrowselect方法中获取图像/单元格标记号。。。!,uitableview,uiimageview,ios6.1,Uitableview,Uiimageview,Ios6.1,Hi-am在带有标记的cellrow中使用2 UIImageView,通过填充数组中的图像(如第0行的图像,第1行的图像)和第1行的图像(第2行的图像,第3行的图像)来顺序显示每一行,依此类推 我成功地为每个图像显示了带有适当标记的图像,但在didrowselect方法中未能获得图像或单元格的标记…我需要标记号直接将标记号作为数组索引传递给detailsegue…我对IOS编程不熟悉,我想知道我在这里是否做错了什么,请建议一种获得适当标签号的方法…非常感谢您在这方面的帮助,因为我只知道这项任务将
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//Check Even Rows or odd rows
if(_objects.count%2==0)
{
return (_objects.count/2);
}
else
{
return ((_objects.count/2)+1);
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyCellIdentifier = @"MyCellIdentifier";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:MyCellIdentifier];
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyCellIdentifier];
}
NSInteger itemcount = _objects.count;
NSLog(@"RowCount:%d",_objects.count/2);
if(itemcount%2==0)
{
NSLog(@"Image Count is Even!");
if(itemcount!=self.tagnumber)
{
RSSItem *object = _objects[self.tagnumber];
UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(10, 4, 145, 95)];
imageView1.tag = self.tagnumber;//1;
NSLog(@"Tag number for Image1:%d", self.tagnumber);
imageView1.image = [UIImage imageWithData:object.artimageData];
[imageView1 setContentMode:UIViewContentModeScaleAspectFill];
[imageView1 setClipsToBounds:YES];
[cell.contentView addSubview:imageView1];
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 100, 145, 30)];
label1.tag = self.tagnumber;
[label1 setFont:[UIFont fontWithName:@"AppleGothic" size:14.0]];
[label1 setTextColor:[UIColor blackColor]];
[label1 setContentMode:UIViewContentModeScaleToFill];
[label1 setTextAlignment:NSTextAlignmentCenter];
label1.text = @"Added 2days ago";;
[label1 setNumberOfLines:1];
[cell.contentView addSubview:label1];
//Display next Image
self.tagnumber++;
object = _objects[self.tagnumber];
UIImageView *imageView2= [[UIImageView alloc]initWithFrame:CGRectMake(165, 4, 145, 95)];
imageView2.tag =self.tagnumber;
NSLog(@"Tag number for Image2:%d", self.tagnumber);
imageView2.image = [UIImage imageWithData:object.artimageData];
[imageView2 setContentMode:UIViewContentModeScaleAspectFill];
[imageView2 setClipsToBounds:YES];
[cell.contentView addSubview:imageView2];
UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(165, 100, 145, 30)];
label2.tag = self.tagnumber;
[label2 setFont:[UIFont fontWithName:@"AppleGothic" size:14.0]];
[label2 setTextColor:[UIColor blackColor]];
[label1 setContentMode:UIViewContentModeScaleToFill];
[label2 setTextAlignment:NSTextAlignmentCenter];
label2.text = @"Added 3days ago";;
[label2 setNumberOfLines:1];
[cell.contentView addSubview:label2];
self.tagnumber++;
[self dismissMegaAnnoyingPopup];
return cell;
}
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Hide Category view if not
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
//[self performSegueWithIdentifier:@"ShowGalleryDetail" sender:cell];
int rownumber = cell.tag;
//Here i get 0 for rownnumber and even if i use indexpath.row**
NSLog (@"Current Page for article is:%i", rownumber);
}
在
cellforrowatinexpath
方法中,设置UIImageView
的标记或UILabel
的标记
在didselectrowatinexpath
方法中,您可以获得单元格的标记
获取单元格中图像视图或标签的标签,或设置单元格的标签。我为imageview和label设置了一个通用标签,因为它是一个单元格,因此它们会正确显示。。。但是我真的不知道如何在单元格中获取我的imageView的标签号…为什么在图像视图和标签上需要标签?只需在单元格上设置
tagNumber
。由于我只使用一个单元格从一行数组中加载2组图像,我无法为单元格设置标记…我真的很困惑,使用2个按钮加载图像确实通过访问buttonclickevent中的[sender tag]解决了我的问题,但我不确定是否建议使用这种设计!!!您最初的问题是关于在didselectrowatinexpath
方法中获取标记。当点击一行时,将调用此函数。从这个方法中,无法确定单元格的哪一部分被点击。我将尝试使用两个单元格,看看它是否真的解决了我的问题…谢谢你的回复,maddy