我如何测试某个表格视图单元格是否具有特定图像?
在我的应用程序中,您可以添加和删除单元格。我只希望用户能够为每个单元格添加 1 个。那么,有没有办法测试一个细胞是否已经拥有某个图像呢?
喜欢:
if(myTableView.cell.imageView == @"image.png"){
// do something
}
请帮忙!谢谢
编辑
此按钮允许我们将单元格和图像添加到新单元格中。
- (IBAction)outlet1:(id)sender {
if (cart.cell.tag == 1) {
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"You have already added this" message:@"Go to My Cart and add more if you like" delegate:self cancelButtonTitle:@"Done" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
else {
[cart.cells addObject:@"1"];
[[cart.cells lastObject] setTag:1];
UIImage * myImage = [UIImage imageNamed:@"paddle1.png"];
[cart.imageArray addObject:myImage];
} 所以
我基本上想测试这个单元格是否已经被添加!
In my app, you can add and delete cells. I only want the user to be able to add 1 of each cell. So, is there a way to test if a cell already has a certain image?
like:
if(myTableView.cell.imageView == @"image.png"){
// do something
}
Please help! THanks
EDIT
This button allows us to add the cells and the images to the new cells.
- (IBAction)outlet1:(id)sender {
if (cart.cell.tag == 1) {
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"You have already added this" message:@"Go to My Cart and add more if you like" delegate:self cancelButtonTitle:@"Done" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
else {
[cart.cells addObject:@"1"];
[[cart.cells lastObject] setTag:1];
UIImage * myImage = [UIImage imageNamed:@"paddle1.png"];
[cart.imageArray addObject:myImage];
}
}
so i basically want to test if this cell has been added already!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您只有几个不同的图像,则不需要检查图像,而是应该使用以下命令为与图像对应的单元格设置标签号
[单元格设置标签:(int)];所以 paddle2.png 可以是 2, paddle1.png 可以是 1,你可以 [cell setTag:1] 表示 paddle1.png 。比测试时简单地检查标签:
If ([cell tag] == 1) {
//做某事
这是您
的按钮的代码:
这是测试代码:
If you only have a few different images than you don't need to check for an image, rather you should set a tag number to the cell that corresponds to an image using
[cell setTag:(int)]; so paddle2.png can be 2 and paddle1.png can be 1 and you would [cell setTag:1] for paddle1.png . Than when testing simply check the tag:
If ([cell tag] == 1) {
//do something
}
here is the code for your button:
and here is the test code:
据我所知,您无法检查图像名称,但您可以保留存储在单元格中的图像名称数组。然后,您可以检查行的索引和图像数组名称的索引,看看它是否是您要查找的内容:
上面的“i”将是indexPath.row值 - 我假设您在委托方法 didSelectRowAtIndexPath。
As far as I know you cannot check for an image name, but you can keep an array of the images names that are stored in the cells. Then you can check the index of the row and the index of the image array names to see if it is what you are looking for:
'i' above would be the indexPath.row value - I am assuming that you are check this on the delegate method didSelectRowAtIndexPath.