【发布时间】:2016-07-01 05:35:00
【问题描述】:
有人可以建议我如何在 Objective C 中实现以下内容吗?
当我单击该特定部分的部分行时,单独展开。我如何知道单击了哪个部分以及如何返回该特定部分的行数?
注意:我在我的部分保留了一个按钮。当我点击所有部分的行时,所有部分的行都会被展开,而当我再次点击一个部分时,所有部分的行都会被折叠。
【问题讨论】:
标签: ios objective-c uitableview rows sections
有人可以建议我如何在 Objective C 中实现以下内容吗?
当我单击该特定部分的部分行时,单独展开。我如何知道单击了哪个部分以及如何返回该特定部分的行数?
注意:我在我的部分保留了一个按钮。当我点击所有部分的行时,所有部分的行都会被展开,而当我再次点击一个部分时,所有部分的行都会被折叠。
【问题讨论】:
标签: ios objective-c uitableview rows sections
注意:- 我的 TableView Cell 高度是 126,但是当我运行我的应用程序时,TableCell 高度是 75(如下所述),当我按下 TableCell 时,TableCell 高度会自动扩展。
参见:- int myCurrentSelection=9999; // 全局设置。
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
int myrow = (int)indexPath.row;
if (myCurrentSelection == myrow) {
myCurrentSelection = 9999;
cell.contentView.backgroundColor = [UIColor whiteColor];
} else {
myCurrentSelection = myrow;
cell.contentView.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1.0];
}
[tableView beginUpdates];
[tableView endUpdates];
[self.tblView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGSize boundingBox = [mutArrMessages [indexPath.row][@"message"] boundingRectWithSize:CGSizeMake((self.tblView.frame.size.width - 86),MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName:[UIFont helveticaNeueLightFontOfSize:17.0]}
context:nil].size;
CGSize size = CGSizeMake(ceil(boundingBox.width), ceil(boundingBox.height));
if ([indexPath row] == myCurrentSelection) {
return (MAX((size.height + 46),76)) + 50;
}
return (MAX((size.height + 46),76));
}
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 76;
}
【讨论】: