Can not get uitoolbar in expandable cell to hide

末鹿安然 提交于 2019-12-25 08:25:58

问题


Hello I am currently using Simon Lee's wonderful tutorial to expand my cells. Everything is working fine.

My cells are 100px, and when expanded the cell becomes 144px high. In the added 44px I have placed a toolbar with bar buttons. I've gotten the buttons to work but there is one problem.

When the cell is expanded I can tap any of the 100px and the cell closes, however when the cell is closed , tapping on the lower 44px of the cell causes the bar buttons to fulfill their actions. I'm assuming that it's still enabled if when hidden from site.

I have disabled user interaction in storyboard but can not get it to turn on when cell is selected and vice versa! If anyone could point me in the right direction that would work!

Simon said something about doing the following, but I'm not quite sure on where to exactly implement it! I've tried it everywhere!

for(NewsCell *cell in [self.tableView visibleCells]) {
    BOOL cellIsSelected = [selectedIndexes objectForKey:indexPath];
    [cell.detailToolbar setUserInteractionEnabled:cellIsSelected];
}

And here's some of my code:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
// If our cell is selected, return double height

if([self cellIsSelected:indexPath]) {

return 144.0;

}

// Cell isn't selected so return single height

return 100.0;
}

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

// Deselect
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];

self.tableView.clipsToBounds = YES;


// Store cell 'selected' state keyed on indexPath
NSNumber *selectedIndex = [NSNumber numberWithBool:isSelected];
[selectedIndexes setObject:selectedIndex forKey:indexPath]; 

// This is where magic happens...
[self.tableView beginUpdates];
 [self.tableView endUpdates];
}

回答1:


The clipsToBounds for the tableView in the didSelectRowAtIndexPath looks a little strange to me

self.tableView.clipsToBounds = YES;

Did you set the clipoToBounds to YES for your cells?




回答2:


I figured it out on my own. It turns out that all I had to do was set the user interaction in my cell to off. and switch it on for the selected cell.

for(NewsCell *cell in [self.tableView visibleCells]) {
        BOOL cellIsSelected = isSelected;
        [cell.detailToolbar setUserInteractionEnabled:cellIsSelected];
}


来源:https://stackoverflow.com/questions/10662376/can-not-get-uitoolbar-in-expandable-cell-to-hide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!