我是 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/