Jap*_*apa 4 height uitableview cgfloat
我有一个桌面视图,我在故事板中设计了多个原型单元格,但我遇到了高度问题,因为我的第一个单元格与第二个单元格不同,依此类推...我对每个单元格都有不同的标识符,因为我在故事板中设计它们,我知道它们的高度.我在我的代码中有这个,但它不起作用,有谁知道如何解决它?:
-(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;
}
Run Code Online (Sandbox Code Playgroud)
}
谢谢你的时间.
看起来您正在尝试将此方法用于不是为...而设计的目的:您将要覆盖该方法:
-(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;
}
Run Code Online (Sandbox Code Playgroud)
仅更改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;
}
Run Code Online (Sandbox Code Playgroud)
查看本教程 http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1这是一个很好的资源
| 归档时间: |
|
| 查看次数: |
3401 次 |
| 最近记录: |