简体   繁体   English

UITableViewCell的附件视图按钮未在ipad纵向模式下显示

[英]UITableViewCell's Accessory View Button is not displaying in ipad portrait mode

I'm new to ios.Please guide me if you found something wrong. 我是ios新手,如果发现错误,请指导我。 Here is my scenario. 这是我的情况。 UITableViewCell is showing a label and a button. UITableViewCell正在显示标签和按钮。 Button should appears only when the cell is selected. 仅当选择单元格时,按钮才应出现。 As sometime they both get overlaps if label text is large. 有时,如果标签文本很大,它们都会重叠。 So decided to add button as Accessory view. 因此决定将按钮添加为附件视图。 Adding button to UITableViewCell's Accessory View is working in iPhone. 在iPhone中,向UITableViewCell的“附件视图”添加按钮正在工作。 Button appears in iPad landscape mode only.Its not showing button in iPad portrait mode. 按钮仅在iPad横向模式下显示,在iPad纵向模式下不显示按钮。 Did I miss something. 我错过了什么。 Is there anyone found something similar. 有没有人发现类似的东西。

- (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;
}

}

It just shows join button in portrait mode only when its already showing in landscape mode and then you change rotation from landscape to portrait. 仅当连接按钮已经以横向模式显示时,它才以纵向模式显示联接按钮,然后将旋转从横向更改为纵向。 Again clicking on some other cell does not show button on that particular selected cell. 再次单击其他某个单元格不会在该特定所选单元格上显示按钮。 Ideally it should show button every time you click on cell in both orientation mode. 理想情况下,每次在双向模式下单击单元格时,它都应显示按钮。

Thanks 谢谢

Are you reloading table view on rotation? 您是否正在重新加载旋转的表格视图?

You have done coding for (cell.accessoryView = joinButton;)in didSelectRowAtIndexPath instead do coding in cellForRowAtIndexPath of UITableViewDataSource or in a willDisplayCell of UITableViewDelegate. 您已经在didSelectRowAtIndexPath中完成了(cell.accessoryView = joinButton;)的编码,而不是在UITableViewDataSource的cellForRowAtIndexPath中或UITableViewDelegate的willDisplayCell中进行了编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM