【问题标题】:UITableViewCell's Accessory View Button is not displaying in ipad portrait modeUITableViewCell 附件视图按钮未在 ipad 纵向模式下显示
【发布时间】:2013-10-28 05:54:17
【问题描述】:

我是 ios 新手。如果您发现有问题,请指导我。这是我的场景。 UITableViewCell 显示一个标签和一个按钮。只有在选择单元格时,才会出现按钮。如果标签文本很大,有时它们都会重叠。因此决定将按钮添加为附件视图。将按钮添加到 UITableViewCell 的附件视图正在 iPhone 中工作。按钮仅在 iPad 横向模式下出现。在 iPad 纵向模式下不显示按钮。我错过了什么。有没有人发现类似的东西。

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

UITableViewCell *cell = [tview cellForRowAtIndexPath:indexPath];
cell.accessoryView = joinButton;

}

- (void)tableView:(UITableView *)tView didDeselectRowAtIndexPath:(NSIndexPath   *)indexPath {
UITableViewCell *cell = [tView cellForRowAtIndexPath:indexPath];
 cell.accessoryView = nil;

}
- (void)viewDidLoad{

NSString *joinLabel = NSLocalizedString(@"Join", @"");
self.joinButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[joinButton setTitle:joinLabel forState:UIControlStateNormal];
/* set join button frame **/
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if (cell.isSelected) {
    cell.accessoryView = joinButton; // No reason to create a new one every time, right?
}
else {
    cell.accessoryView = nil;
}

}

只有当它已经以横向模式显示时,它才以纵向模式显示加入按钮,然后您将旋转从横向更改为纵向。再次单击某个其他单元格不会在该特定选定单元格上显示按钮。理想情况下,每次在两种方向模式下单击单元格时,它都应该显示按钮。

谢谢

【问题讨论】:

    标签: ios ipad uitableview accessoryview


    【解决方案1】:

    您是否正在重新加载旋转时的表格视图?

    您已经在 didSelectRowAtIndexPath 中完成了 (cell.accessoryView = joinButton;) 的编码,而不是在 UITableViewDataSource 的 cellForRowAtIndexPath 或 UITableViewDelegate 的 willDisplayCell 中进行编码。

    【讨论】:

    • 我也完成了 willDisplayCell 的编码,我已经更新了我的代码
    猜你喜欢
    • 2016-05-28
    • 1970-01-01
    • 1970-01-01
    • 2014-03-26
    • 1970-01-01
    • 1970-01-01
    • 2021-12-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多