customCell 图像在 didSelectRowAtIndexPath 上没有响应(但在其他方面有效)

发布于 2024-12-29 11:37:01 字数 1491 浏览 2 评论 0原文

我有一个很好的 UITableView 自定义单元格,一切正常。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = nil;

    CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {

        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];

        for (id currentObject in topLevelObjects){
            if ([currentObject isKindOfClass:[UITableViewCell class]]){
                cell =  (CustomCell *) currentObject;
                break;
            }
        }
    }


    // LOOK HERE: cellArrowPointingRight is an UIImage view of which I like to turn on later
    [cell.cellArrowPointingRight setHidden:YES];
    // The above line works as it hides all cellArrowPointingRight(s)

    return cell;
}

在自定义视图(在IB中制作)中我也有cellArrowPointingRight(它连接到M中的H和@synthesize cellArrowPointingRight,

问题是我在选择单元格时无法运行它

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {



    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
   // cell.contentView.backgroundColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.5];
   cell.textLabel.text = @"Clicked";
  // PROBLEM HERE: (cellArrowPointingRight is not legal)
  [cell.cellArrowPointingRight setHidden:NO]; 
} 

我该如何解决这个问题?

I have my a nice customCell for UITableView , all works well.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = nil;

    CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {

        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];

        for (id currentObject in topLevelObjects){
            if ([currentObject isKindOfClass:[UITableViewCell class]]){
                cell =  (CustomCell *) currentObject;
                break;
            }
        }
    }


    // LOOK HERE: cellArrowPointingRight is an UIImage view of which I like to turn on later
    [cell.cellArrowPointingRight setHidden:YES];
    // The above line works as it hides all cellArrowPointingRight(s)

    return cell;
}

in the custom view (made in IB) I also have cellArrowPointingRight (it is connected to the H and @synthesize cellArrowPointingRight in the M

problem is that I can not run it on when selecting a cell

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {



    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
   // cell.contentView.backgroundColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.5];
   cell.textLabel.text = @"Clicked";
  // PROBLEM HERE: (cellArrowPointingRight is not legal)
  [cell.cellArrowPointingRight setHidden:NO]; 
} 

How do I solve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最美的太阳 2025-01-05 11:37:02

当您使用时:

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

默认单元格通常不应该有一个名为 cellArrowPointingRight 的字段,因此普通的 UITableViewCell 不会对此做出响应。

您需要做的是将单元格获取为:

CustomCell *cell = (CustomCell*)[tableView cellForRowAtIndexPath:indexPath];

假设您的 CustomCell 是 UITableViewCell 的超类。

As you are using :

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

That default cell should not normally have a field called cellArrowPointingRight therefore a normal UITableViewCell would not respond to that.

What you need to do is to get the cell as :

CustomCell *cell = (CustomCell*)[tableView cellForRowAtIndexPath:indexPath];

Assuming that your CustomCell is a superclass of UITableViewCell.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文