【发布时间】:2016-02-08 10:06:49
【问题描述】:
这里我正在开发一个扩展 TableViewCell ,而 TableView didSelectRowAtIndexPath 方法我用来扩展单元格,这里我使用了两个 TableView 单元格
但我需要按钮操作 SecondCell 将被展开。你能帮我如何实现这里是下面的代码,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// disable touch on expanded cell
UITableViewCell *cell = [self.theTableView cellForRowAtIndexPath:indexPath];
if ([[cell reuseIdentifier] isEqualToString:@"ExpandedCellIdentifier"]) {
return;
}
// deselect row
[tableView deselectRowAtIndexPath:indexPath
animated:NO];
// get the actual index path
indexPath = [self actualIndexPathForTappedIndexPath:indexPath];
// save the expanded cell to delete it later
NSIndexPath *theExpandedIndexPath = self.expandedIndexPath;
// same row tapped twice - get rid of the expanded cell
if ([indexPath isEqual:self.expandingIndexPath]) {
self.expandingIndexPath = nil;
self.expandedIndexPath = nil;
}
// add the expanded cell
else {
self.expandingIndexPath = indexPath;
self.expandedIndexPath = [NSIndexPath indexPathForRow:[indexPath row] + 1
inSection:[indexPath section]];
}
[tableView beginUpdates];
if (theExpandedIndexPath) {
[_theTableView deleteRowsAtIndexPaths:@[theExpandedIndexPath]
withRowAnimation:UITableViewRowAnimationNone];
}
if (self.expandedIndexPath) {
[_theTableView insertRowsAtIndexPaths:@[self.expandedIndexPath]
withRowAnimation:UITableViewRowAnimationNone];
}
[tableView endUpdates];
// scroll to the expanded cell
[self.theTableView scrollToRowAtIndexPath:indexPath
atScrollPosition:UITableViewScrollPositionMiddle
animated:YES];
}
但我想在点击按钮时实现 secondCell 将展开。
- (IBAction)expand:(id)sender {
}
你能帮帮我吗,谢谢。
【问题讨论】:
标签: ios objective-c iphone xcode tableviewcell