Uitableview 在不同部分设置不同的行高(故事板)
我在故事板中设计了一个包含多个原型单元的tableview,但我一直在解决高度问题,因为我的第一个单元与第二个单元不同,以此类推……我对每个单元都有不同的标识符,因为我在故事板中设计了它们,我知道它们是高度的。我的代码中有这个,但它不起作用,有人知道如何修复它吗Uitableview 在不同部分设置不同的行高(故事板),uitableview,height,cgfloat,Uitableview,Height,Cgfloat,我在故事板中设计了一个包含多个原型单元的tableview,但我一直在解决高度问题,因为我的第一个单元与第二个单元不同,以此类推……我对每个单元都有不同的标识符,因为我在故事板中设计了它们,我知道它们是高度的。我的代码中有这个,但它不起作用,有人知道如何修复它吗 -(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cel
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc]init];
switch (indexPath.section)
{
case 1:
cell = [tableView dequeueReusableCellWithIdentifier:@"cell1"];
return 743.0f;
break;
case 2:
cell = [tableView dequeueReusableCellWithIdentifier:@"cell2"];
return 300.0f;
}
}
谢谢您的时间。看起来您正试图将此方法用于它不是为……而设计的目的。。。 您将要覆盖该方法:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
switch (indexPath.section)
case 1:
static NSString *CellIdentifier = @"cell1";
break;
case 2:
static NSString *CellIdentifier = @"cell2";
break;
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
return cell;
}
仅在heightForRowAtIndexPath中更改行高:
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
switch (indexPath.section)
{
case 1:
return 743.0f;
break; //technically never used
case 2:
return 300.0f;
}
查看本教程这是一个很好的资源谢谢!!!班多卡尔,问题终于解决了。我也没有提到,但它给了我另一个问题(知道解决了!),每次我进入编辑模式(我有多个分组部分)时,当我想要另一行时(按下绿色的加号按钮),行的内容都乱七八糟。我指的是创建的新行(第一节743.0f的副本),站在第二部分的顶部…知道一切都好,再次感谢。欢迎来到堆栈溢出(SO)Japa!既然BandoKal回答了您的问题,请务必单击他答案旁边的复选标记,以表彰他对您的帮助!此外,一旦你获得了10分的声誉,你还可以通过点击向上箭头,向上投票所有有帮助的答案,这也给了花时间帮助你的人声誉!