Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何在UITableViewCell中标记UIImage_Iphone_Objective C_Uitableview_Uiimageview_Uiimage - Fatal编程技术网

Iphone 如何在UITableViewCell中标记UIImage

Iphone 如何在UITableViewCell中标记UIImage,iphone,objective-c,uitableview,uiimageview,uiimage,Iphone,Objective C,Uitableview,Uiimageview,Uiimage,我想切换UITableViewCell image-cell.imageView.image。(如红绿) 如果当前图像为绿色,则当用户单击UITableViewCell时,图像将变为红色 一旦我设置了图像 cell.imageView.image = [UIImage imageNamed:@"Green.png"]; 如何检测单元格当前使用的图像 谢谢你的帮助 在imageView本身上设置: #define IMAGE_TAG_GREEN 50 #define IMAGE_TAG_RED

我想切换UITableViewCell image-cell.imageView.image。(如红绿)

如果当前图像为绿色,则当用户单击UITableViewCell时,图像将变为红色

一旦我设置了图像

cell.imageView.image = [UIImage imageNamed:@"Green.png"];
如何检测单元格当前使用的图像

谢谢你的帮助

imageView
本身上设置:

#define IMAGE_TAG_GREEN 50
#define IMAGE_TAG_RED   51

-(UITableViewCell*) tableView:(UITableView*) tableView cellForRowAtIndexPath:(NSIndexPath *) indexPath {
  static NSString *CELL_ID = @"some_cell";
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CELL_ID];
  if(cell == nil) {
     //do setup here...
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CELL_ID] autorelease];
     cell.imageView.tag = //some logic here...
  }
  if(cell.imageView.tag == IMAGE_TAG_GREEN) {
    //...
  } else {
    //...
  }
  return cell;
}
由于
tag
是从
UIView
继承的属性,因此不能将其与
UIImage
本身一起使用,但可以与
UIImageView

一起使用,在
imageView
本身上设置:

#define IMAGE_TAG_GREEN 50
#define IMAGE_TAG_RED   51

-(UITableViewCell*) tableView:(UITableView*) tableView cellForRowAtIndexPath:(NSIndexPath *) indexPath {
  static NSString *CELL_ID = @"some_cell";
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CELL_ID];
  if(cell == nil) {
     //do setup here...
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CELL_ID] autorelease];
     cell.imageView.tag = //some logic here...
  }
  if(cell.imageView.tag == IMAGE_TAG_GREEN) {
    //...
  } else {
    //...
  }
  return cell;
}

由于
tag
是从
UIView
继承的属性,因此不能将其与
UIImage
本身一起使用,但可以与
UIImageView

一起使用,这有点粗糙,但您应该能够设置如下所示的if语句:

if ([cell.imageView.image isEqual:[UIImage imageNamed:@"Green.png"]]) {
    // image is green;
} else {
    // image is red;
}

我对它进行了测试,只是为了确保它工作正常

它有点粗糙,但您应该能够设置如下所示的if语句:

if ([cell.imageView.image isEqual:[UIImage imageNamed:@"Green.png"]]) {
    // image is green;
} else {
    // image is red;
}

我对它进行了测试,只是为了确保它工作正常

我对这方面还不熟悉,但我想你可以使用if/then语句

If (cell.imageView.image = [UIImage imageNamed:@"Green.png"]) {
    cell.imageView.image = [UIImage imageNamed:@"Green.png"];
} else
{
    cell.imageView.image = [UIImage imageNamed:@"Red.png"];
}
或者你可以去真正的幻想和使用。类似于以下内容(请注意,下面的代码可能是错误的,但希望能帮助您入门!)

让我们知道你是怎么做的


Kolya

我对这一点还不熟悉,但我想你可以使用if/then语句

If (cell.imageView.image = [UIImage imageNamed:@"Green.png"]) {
    cell.imageView.image = [UIImage imageNamed:@"Green.png"];
} else
{
    cell.imageView.image = [UIImage imageNamed:@"Red.png"];
}
或者你可以去真正的幻想和使用。类似于以下内容(请注意,下面的代码可能是错误的,但希望能帮助您入门!)

让我们知道你是怎么做的


Kolya

我相信只要添加一个布尔表达式,如果它是绿色,则为真;如果它是红色,则为假。 将此布尔表达式设为外部类型,使其成为全局表达式。 单击图像时设置布尔值。
我相信这会有所帮助。

我相信只要添加一个布尔表达式,如果它是绿色,则为真;如果它是红色,则为假。 将此布尔表达式设为外部类型,使其成为全局表达式。 单击图像时设置布尔值。
我相信这会有所帮助。

这比像我这样简单地比较
int
s要贵得多。这比像我这样简单地比较
int
s要贵得多。正如前面所说的,不要比较图像,这是昂贵的,甚至在桌面上也是愚蠢的。标签是首选的方式,正如苹果在这里使用的例子:如前所述,不要比较图像,即使是在桌面上,也绝对是愚蠢的。标记是首选的方式,例如苹果在这里使用: