Iphone 是否以编程方式为单个UITableViewCell设置高度?
我需要以编程方式设置UITableView中单个UITableViewCell的高度。我该怎么做 我需要这一个细胞是150像素高,所有其他可以保持在默认的44像素的高度 谢谢Iphone 是否以编程方式为单个UITableViewCell设置高度?,iphone,objective-c,uitableview,Iphone,Objective C,Uitableview,我需要以编程方式设置UITableView中单个UITableViewCell的高度。我该怎么做 我需要这一个细胞是150像素高,所有其他可以保持在默认的44像素的高度 谢谢 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 您可以使用此方法为特定索引路径上的单元格设置值,并为其他单元格设置默认值。UITableViewCell高度有一个委托函数 在这里,
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
您可以使用此方法为特定索引路径上的单元格设置值,并为其他单元格设置默认值。UITableViewCell高度有一个委托函数 在这里,您可以指定该特定单元格的indexPath并返回其高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.section == yourSection && indexPath.row == yourRow) {
return 150.0;
}
// "Else"
return someDefaultHeight;
}
你必须知道,或者弄清楚你想把哪个单元格索引变成更高的。 假设这是你的第一个手机
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) { //change 0 to whatever cell index you want taller
return 150;
}
else {
return 44;
}
}
快速回答 在
heightforrowatinexpath
方法中指定要更改的节和行(记住计数从0开始,而不是从1开始)
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat{
if indexPath.section == 0 && indexPath.row == 0{
return 150
}
return 44.0
}