表视图有两个"列"?

Jas*_*son 0 uitableview ios

我是Xcode和Objective C的新手,但我似乎无法在我想创建的简单表上找到教程.我想要一个只有三行但两列的表(分组样式).A列有一个标签(如'Name:'),B列有实际数据("Jason").

我似乎无法找到如何做到这一点.除非我只是完全查找错误的东西?希望有人可以帮助我如何做到这一点或指出我正确的方向.

谢谢!!

Mat*_*uch 7

您不想使用包含2列的表.它们不在iOS中使用.
你应该使用UITableViewCell一个UITableViewCellStyleValue2风格.而你要设置@"Name"textLabel.text@"Jason"作为detailTextLabel.text.


UITableView截图

你必须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;
}
Run Code Online (Sandbox Code Playgroud)