ios - 带有两个 "columns"的 TableView ?

标签 ios uitableview

我真的是 Xcode 和 Objective C 的新手,但我似乎找不到关于我想创建的简单表格的教程。我想要一个只有三行两列的表(分组样式)。 A 列有一个标签(如“姓名:”),B 列有实际数据(“Jason”)。

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

谢谢!!

最佳答案

您不想使用包含 2 列的表格。它们未在 iOS 中使用。
您应该使用具有 UITableViewCellStyleValue2 样式的 UITableViewCell。并且您想将 @"Name" 设置为 textLabel.text 并将 @"Jason" 设置为 detailTextLabel.text .


UITableView screenshot

您必须稍微更改 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/

相关文章:

ios - 数据库中的组名。仅显示一组名称 UITableView 行

javascript - 本地 laravel API 上的 Nativescript-Vue axios 调用错误 [请求失败,状态码为空]

ios - 从 UIButton 发件人返回了错误的 tableViewCell

ios - 当 UIView 中的文本在动画之前更改时,为什么 UIView 动画会失败?

ios - Swift 中是否有 PrettyTime 函数

ios - 以编程方式设置提示时,UINavigationBar 与 UITableView 重叠

ios - swift -UITableView 'unable to dequeue a cell with identifier Cell'

ios - 滚动到特定标题 View

iphone - 如何从 UITableView iphone 获取 UITableView IndexPath?

objective-c - Cocos2D CCScene 黑屏,没有任何反应?