是否可以检查uitableviewcell accessoryview是否包含图像?
例如
if([self.tableView cellForRowAtIndexPath:indexPath].accessoryView == [UIImage imageNamed:@"selected.png"] ) 有些像这样,或者用不同的方法。
谢谢
发布于 2011-06-09 18:51:59
默认情况下,accessoryView将为空。
你可以检查一下-
if (self.tableView.accessoryView) {
// An image is present
}发布于 2011-06-09 18:46:30
对于我的应用程序,我创建了一个自定义单元格,然后在contentView中添加了imageView
但是对于你的需求,你可以这样做
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
cell.accessoryView = imageView];
imageView.tag = 3;
[imageView release];
}
NSArray *subviews = [[NSArray alloc] initWithArray:cell.contentView.subviews];
UIImageView *imageView;
for (UIView *subview in subviews)
{
if([subview isKindOfClass:[UIImageView class]] && subview.tag == 3);
imageView = [subview copy];
}
[subviews release];
if([selectedArray containsObject:indexPath])
imageView.image = [UIImage imageNamed:@"Selected.png"];
else
imageView.image = [UIImage imageNamed:@"Unselected.png"];
}在此方法中,执行相同的操作以获取imageView对象
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath发布于 2011-06-09 18:56:45
首先:
if([self.tableView cellForRowAtIndexPath:indexPath].accessoryView == [UIImage imageNamed:@"selected.png"] )
这是错误的..。acessaryview不是一个图像,它是UIView。
检查以下内容:
if(nil != [self.tableView cellForRowAtIndexPath:indexPath].accessoryView)
{
// It has got something in it...
}
else
{
//create an accessary view....
}https://stackoverflow.com/questions/6291391
复制相似问题