Ale*_*der 1 xcode objective-c uitableview
我正在努力实现以下效果:
到目前为止,我有一个侦听单击的工作函数:
- (void)handleSingleTap:(UITapGestureRecognizer *)gestureRecognizer {
CGPoint p = [gestureRecognizer locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:p];
if(indexPath != nil) {
[self.tableView beginUpdates];
*Call heightForRowAtIndexPath here?*
[self.tableView endUpdates];
}
}
Run Code Online (Sandbox Code Playgroud)
我的heightForRowAtIndexPath:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"runs");
return 64;
}
Run Code Online (Sandbox Code Playgroud)
至于我已经能够在网上的不同网站的帮助下弄清楚,我必须在[self.tableView beginUpdates]和之间以某种方式调用该函数[self.tableView endUpdates].但是我该怎么做?我对Xcode或Objective C并不熟悉,所以我们将不胜感激!
提前致谢.
亚历山大.
你不打电话给tableView:heightForRowAtIndexPath:自己.tableView将调用它.tableView将在您发送endUpdates给它之后调用该方法.您必须从调用tableView:heightForRowAtIndexPath:之后返回不同的值handleSingleTap:.
您可以通过在属性(或实例变量)tableView:heightForRowAtIndexPath:中保存扩展的indexPath ,并在请求的indexPath与保存的扩展indexPath匹配时返回不同的值来执行此操作.
例如
@property (strong, nonatomic) NSIndexPath *expandedIndexPath;
- (void)handleSingleTap:(UITapGestureRecognizer *)gestureRecognizer {
CGPoint p = [gestureRecognizer locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:p];
if(indexPath != nil) {
self.expandedIndexPath = indexPath;
[self.tableView beginUpdates];
[self.tableView endUpdates];
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"runs");
if (self.expandedIndexPath && [indexPath isEqual:self.expandedIndexPath]) {
// expanded cell
return 200;
}
else {
return 64;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4219 次 |
| 最近记录: |