ios - 如何使用 Xcode 访问 NSArray 中的特定列

标签 ios xcode

我是 iOS 编程新手。我正在尝试将数组中对象的特定字段绑定(bind)到 UITableView。这是我的代码:

NSArray *personInfo; //contains a record with fields: name, address, email

personInfo = [[PersonDatabase database] getAllPersons]; //pulling the record into array

从那里,我尝试从数组中获取字段“name”。

cell.textLabel.text = [NSString stringWithFormat:@"%@", [personInfo objectAtIndex: indexPath.row] retain]

最佳答案

由于数组中似乎有对象,因此您可能正在寻找 -[NSArray valueForKey:] 方法 ( documentation here )。

例如:

NSArray *names = [personInfo valueForKey:@"name"];

这应该返回一个包含数组中所有名称的数组。

关于ios - 如何使用 Xcode 访问 NSArray 中的特定列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8485739/

相关文章:

xcode - XCode中的星号“*”之间有什么区别?

ios - 如何禁用 UIScrollView 的垂直滚动?

objective-c - 检测文本字段中的某些字符

ios - 如何在我的 Swift XCode 应用程序上设置 SwiftyJSON?

javascript - iscroll 不会自动工作

ios - 如何从 UiTableViewCell 更改 View Controller 中字典的值

c - 无法编译 pjsua 二进制文件

xcode - OS X Mavericks 中的自定义登录/锁定屏幕

ios - 从在线 JSON 文件更新 JSON 本地文件

ios - 将数据从 Swift View Controller 传递到 Objective-C View Controller