【问题标题】:can i give space between two cells in tableview in ipohne?我可以在 iphone 的 tableview 中的两个单元格之间留出空间吗?
【发布时间】:2013-03-30 11:17:41
【问题描述】:
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

NSLog(@"%d",indexId);
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    /////////////////////   Cell Title    /////////////////////
    //cell.textLabel.font = [UIFont fontWithName:@"Noteworthy" size:20.0];
    cell.textLabel.font = [UIFont boldSystemFontOfSize:14.0];
    cell.textLabel.highlightedTextColor = [UIColor orangeColor];
}
/////////////////////   Cell Title    /////////////////////
cell.textLabel.text = [NSString stringWithFormat:@"  %@", [test.arrTitle objectAtIndex:indexPath.row]];

上面的代码我需要更改代码以获取 tableview 单元格标签之间的空间

感谢和问候

【问题讨论】:

标签: iphone uitableview


【解决方案1】:

有几种方法可以在表格视图中的单元格之间添加空间。

您可以在 Interface Builder 中调整表格视图单元格的高度,您可以自定义具有不同高度的单元格,或者您可以通过tableView:heightForRowAtIndexPath: 委托方法以编程方式返回不同的高度。

【讨论】:

  • 谢谢@Michael。问两个表格视图单元格之间的空间而不是高度?
  • 您是否在单元格之间显示分隔线?你想要额外的分隔线,它们之间有空格吗?或者没有分隔线,只有额外的空格(在这种情况下我的答案仍然很好)。
【解决方案2】:

在两个单元格之间添加空格的一种简单方法是使用这些部分来显示数据。确保每个部分只包含一个单元格。然后,您可以在后续部分之间添加 sectionHeaderView 或 sectionFooterView 以使其正确。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  return [myItems count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
 return 1;
}

#define customSeparatorHeight 3
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  return [UIView alloc] initWithFrame:CGRectMake(0,0, tableView.bounds.size.width, customSeparatorHeight)];
}

【讨论】:

    猜你喜欢
    • 2011-11-03
    • 1970-01-01
    • 1970-01-01
    • 2013-04-01
    • 2020-08-17
    • 1970-01-01
    • 1970-01-01
    • 2016-07-12
    • 1970-01-01
    相关资源
    最近更新 更多