UITableViewCell定制配件

编程入门 行业动态 更新时间:2024-10-24 02:34:45
本文介绍了UITableViewCell定制配件 - 获取一排配件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个很大的问题。我想在 UITableView 中的每个 UITableViewCell 上创建一个收藏夹按钮。这非常好,我按下时会执行一个动作和选择器。

I have a pretty big issue. I am trying to create a favorite-button on every UITableViewCell in a UITableView. That works very good, and I currently have an action and selector performed when pressed.

accessory = [UIButton buttonWithType:UIButtonTypeCustom]; [accessory setImage:[UIImage imageNamed:@"star.png"] forState:UIControlStateNormal]; accessory.frame = CGRectMake(0, 0, 15, 15); accessory.userInteractionEnabled = YES; [accessory addTarget:self action:@selector(didTapStar) forControlEvents:UIControlEventTouchUpInside]; cell.accessoryView = accessory;

选择器:

- (void) didTapStar { UITableViewCell *newCell = [tableView cellForRowAtIndexPath:/* indexPath? */]; accessory = [UIButton buttonWithType:UIButtonTypeCustom]; [accessory setImage:[UIImage imageNamed:@"stared.png"] forState:UIControlStateNormal]; accessory.frame = CGRectMake(0, 0, 26, 26); accessory.userInteractionEnabled = YES; [accessory addTarget:self action:@selector(didTapStar) forControlEvents:UIControlEventTouchDown]; newCell.accessoryView = accessory; }

现在,问题在于:我想知道附件是什么排按下属于。 我该怎么做?

Now, here's the problem: I want to know what row the accessory that was pressed belongs to. How can I do this?

谢谢:)

推荐答案

我会使用以下代码:

- (void)didTapStar:(id)sender { NSIndexPath *indexPath = [tableView indexPathForCell:(UITableViewCell *)[sender superview]]; }

更多推荐

UITableViewCell定制配件

本文发布于:2023-11-13 10:36:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584148.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:配件   UITableViewCell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!