Objective c 动态更改tableview行高度
我有一个2行的表视图。初始设置相应的行高度。然后我加载另一个视图控制器,它显示一个列表,用户可以从中选择多个项目。这些项目将作为自定义图像绘制在tableview的第一行上。当用户单击“上一步”时,将显示用户所选项目的选择,但我需要能够调整第0行的高度。尝试以下操作:Objective c 动态更改tableview行高度,objective-c,ios,cocoa-touch,Objective C,Ios,Cocoa Touch,我有一个2行的表视图。初始设置相应的行高度。然后我加载另一个视图控制器,它显示一个列表,用户可以从中选择多个项目。这些项目将作为自定义图像绘制在tableview的第一行上。当用户单击“上一步”时,将显示用户所选项目的选择,但我需要能够调整第0行的高度。尝试以下操作: -(CGFloat)tableView:(UITableView*)tableView row的高度索引路径:(nsindepath*)indepath尝试以下操作: -(CGFloat)tableView:(UITableVie
-(CGFloat)tableView:(UITableView*)tableView row的高度索引路径:(nsindepath*)indepath
尝试以下操作:
-(CGFloat)tableView:(UITableView*)tableView高度for rowatindexpath:(nsindepath*)indepath
在TableListController头文件上声明:
@property (nonatomic, retain) NSIndexPath * expandedCellIndexPath;
然后在.m上添加
- (void)changeCellHeights:(NSIndexPath *)indexPath
{
if (self.expandedCellIndexPath) {
[self.yourTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject: self.expandedCellIndexPath] withRowAnimation:UITableViewRowAnimationFade];
}
self.expandedCellIndexPath = indexPath;
[self.yourTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject: self.expandedCellIndexPath] withRowAnimation:UITableViewRowAnimationMiddle];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
DebugLog(@"");
if (self.expandedCellIndexPath && indexPath.row == self.expandedCellIndexPath.row && indexPath.section == self.expandedCellIndexPath.section) {
return 80;
}
return 56.0;
}
最后,不要忘记将tableCell设置为剪裁子视图(在Xib上,如果使用的话)
现在只需在TableListController头文件上调用changeCellHeights:方法
@property (nonatomic, retain) NSIndexPath * expandedCellIndexPath;
然后在.m上添加
- (void)changeCellHeights:(NSIndexPath *)indexPath
{
if (self.expandedCellIndexPath) {
[self.yourTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject: self.expandedCellIndexPath] withRowAnimation:UITableViewRowAnimationFade];
}
self.expandedCellIndexPath = indexPath;
[self.yourTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject: self.expandedCellIndexPath] withRowAnimation:UITableViewRowAnimationMiddle];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
DebugLog(@"");
if (self.expandedCellIndexPath && indexPath.row == self.expandedCellIndexPath.row && indexPath.section == self.expandedCellIndexPath.section) {
return 80;
}
return 56.0;
}
最后,不要忘记将tableCell设置为剪裁子视图(在Xib上,如果使用的话)
现在只需调用changeCellHeights:方法我已经使用该代码设置初始行高,但当用户选择要显示的项目后返回表时,不会再次触发该方法。可能尝试
[tableview reloadData]
刷新tableview并应用新高度。我已经使用该代码设置初始行高度,但当用户选择要显示的项目后返回表格时,不会再次触发该代码。可能尝试[tableview reloadData]
刷新tableview并应用新高度。选择项目后是否在原始tableview上调用reloadData?我需要检查一下。我相信是这样,但是在选择一个项目后,您是否会在原始tableview上调用reloadData呢?我需要检查一下。我相信是这样,但我会证实