简体   繁体   中英

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. Here is my scenario. UITableViewCell is showing a label and a button. 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. Button appears in iPad landscape mode only.Its not showing button in iPad portrait mode. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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