我真的是 Xcode 和 Objective C 的新手,但我似乎找不到关于我想创建的简单表格的教程。我想要一个只有三行两列的表(分组样式)。 A 列有一个标签(如“姓名:”),B 列有实际数据(“Jason”)。
我似乎无法找到如何做到这一点。除非我只是完全查找错误的东西?希望有人可以帮助我如何做到这一点或指出正确的方向。
谢谢!!
最佳答案
您不想使用包含 2 列的表格。它们未在 iOS 中使用。
您应该使用具有 UITableViewCellStyleValue2
样式的 UITableViewCell
。并且您想将 @"Name"
设置为 textLabel.text
并将 @"Jason"
设置为 detailTextLabel.text
.
您必须稍微更改 tableView:cellForRowAtIndexPath:
。
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = @"Name";
cell.detailTextLabel.text = @"Jason";
return cell;
}
关于ios - 带有两个 "columns"的 TableView ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5260837/