使用自定义 UITableViewCell 的附件视图显示两个项目

发布于 2024-09-13 09:27:40 字数 376 浏览 3 评论 0原文

我已经寻找这个有一段时间了,但还没有找到答案(归咎于糟糕的谷歌搜索技巧)。我有一个自定义 UITableViewCell 类,目前由一个自定义 UISwitch 和一个 UILabel 组成。我想添加一个仅当开关设置为“是”时才可见(且处于活动状态)的按钮。现在,我将开关添加到 accessoryView 中,然后保留它。但是,据我所知,附件视图实际上并没有子视图,所以这是我的问题:

我是否应该创建一个具有按钮和开关的 UIView,调整其大小以适合单元格的附件视图(或者它会自动调整大小吗?),并将其作为单元格的附件视图放入?这是通常的情况吗?

或者有我缺少的解决方案吗?

谢谢。

I've been looking for this for a while, but haven't found an answer (blame poor googling skills). I have a custom UITableViewCell class which, currently, consists of a custom UISwitch and a UILabel. I want to add a button that's only visible (And active) when the switch is set to "Yes". Right now I add the switch to the accessoryView, and leave it. However, the accessory view doesn't really have subviews, as far as I can tell, so here's my question:

Should I just create a UIView that has a button and a switch, size it to fit the cell's accessory view (or will it auto-size itself?), and put that in as the cell's accessory view? And is this typically the way that it's gone about?

Or is there a solution that I'm missing?

Thanks.

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

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

发布评论

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

评论(1

穿透光 2024-09-20 09:27:40

这是一个例子:

UIButton* btdel = [[UIButton alloc] init]; 
btdel.tag = indexPath.row; 
//[btdel setTitle:@"Delete Event" forState:UIControlStateNormal];
[btdel setBackgroundImage:[UIImage imageNamed:@"ButtonRemove.png"] forState:UIControlStateNormal];
[btdel addTarget:self action:@selector(deleteEvent:) forControlEvents:UIControlEventTouchUpInside];
// bt.titleLabel.frame = CGRectMake(0, 0, 95,24); 
btdel.frame = CGRectMake(110, 0, 30,30); 
[headerView addSubview:btdel];
[btdel release];

UIButton* bt = [[UIButton alloc] init]; 
bt.tag = indexPath.row;  
[bt setTitle:@"Select a Dress" forState:UIControlStateNormal];
[bt setBackgroundImage:[UIImage imageNamed:@"findDress.png"] forState:UIControlStateNormal];
[bt addTarget:self action:@selector(showDresses:) forControlEvents:UIControlEventTouchUpInside];

bt.font=[UIFont systemFontOfSize:(CGFloat ) 13];

// bt.titleLabel.frame = CGRectMake(0, 0, 95,24); 
bt.frame = CGRectMake(0, 3, 95,24);

[headerView addSubview:bt];
cell.accessoryView = headerView;

Here is an example:

UIButton* btdel = [[UIButton alloc] init]; 
btdel.tag = indexPath.row; 
//[btdel setTitle:@"Delete Event" forState:UIControlStateNormal];
[btdel setBackgroundImage:[UIImage imageNamed:@"ButtonRemove.png"] forState:UIControlStateNormal];
[btdel addTarget:self action:@selector(deleteEvent:) forControlEvents:UIControlEventTouchUpInside];
// bt.titleLabel.frame = CGRectMake(0, 0, 95,24); 
btdel.frame = CGRectMake(110, 0, 30,30); 
[headerView addSubview:btdel];
[btdel release];

UIButton* bt = [[UIButton alloc] init]; 
bt.tag = indexPath.row;  
[bt setTitle:@"Select a Dress" forState:UIControlStateNormal];
[bt setBackgroundImage:[UIImage imageNamed:@"findDress.png"] forState:UIControlStateNormal];
[bt addTarget:self action:@selector(showDresses:) forControlEvents:UIControlEventTouchUpInside];

bt.font=[UIFont systemFontOfSize:(CGFloat ) 13];

// bt.titleLabel.frame = CGRectMake(0, 0, 95,24); 
bt.frame = CGRectMake(0, 3, 95,24);

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