iphone - iOS:如何查询nsmutablearray对象中的对象

标签 iphone ios objective-c nsmutablearray nsobject

谁能帮我告诉我如何访问 NSMutableArray 中的对象。

对象的创建是这样的:

View Controller :

Students *studens =[[Students alloc] initWithDictionary:data]; //where data is NSDictionary
[self.studentData addObject:studens]; //where studentData is a NSMutableArray

在 Students 中是一个 NSObject 类。在学生类中:

-(id)initWithDictionary:(NSDictionary *)studenDictionary
    self = [super init];
    if (self)
    {
        self.studentName= [stateDictionary objectForKey:@"name"];
        self.studenLastName= [stateDictionary objectForKey:@"lastName"];
        self.StundenAddress= [stateDictionary objectForKey:@"address"];
    }
    return self;
}

如果我 nslog nsmutablearray 我会得到这个输出:

"<studens: 0x756b970>",
"<studens: 0xf46f9a0>"

例如,我的问题是如何访问学生姓名 John 的信息?

最佳答案

在您的Students 类中实现description 方法:

- (NSString *)description {
    return [NSString stringWithFormat:@"Students: name: %@, lastName: %@, address: %@", self.studentName, self.studentLastNAme, self.studentAddress];
}

现在,当您记录数组时,您将看到有关数组中每个 Students 对象的有用信息。

关于iphone - iOS:如何查询nsmutablearray对象中的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17418181/

相关文章:

iphone - 对核心数据对象进行分组

iphone - iPhone 没有网络也能识别大词汇量语音吗?

iphone - 从电子邮件链接启动基于 PhoneGap 的 iPhone 应用程序

ios - 如何设置 UIPageViewController(分页类型)手势委托(delegate)

ios - 访问特定索引中的数组

ios - 我想使用 CorePlot 从图形中删除负数部分?

iphone - 在哪里构建自定义 UITableViewCell : in layoutSubviews or initWithStyle:reuseIdentifier?

ios - 打开 Facebook 页面墙的 URL 在 UIWebView 中不起作用

iphone - Ios应用程序图标类

objective-c - 基于 NSDocument 的应用程序,启动时使用 'New Document' 按钮打开对话框