访问NSArray中的元素

时间:2014-05-07 22:52:37

标签: ios objective-c nsarray

我有两个班级:

MusicQuestion具有此属性:

@property (nonatomic, strong) NSArray *answers; // array of MPMediaItem

MusicQuiz具有此属性:

@property (nonatomic, strong)   NSMutableArray *questions; // array of MusicQuestion

我想从MusicQuiz answers[0] question[0]内访问[self.question[0] answers] // It only access the entire array of the first question 。我试过这个:

{{1}}

我该怎么做?

3 个答案:

答案 0 :(得分:2)

您已经访问过答案数组,现在只需访问数组中的项目:

MPMediaItem *item = [self.question[0] answers][0];

答案 1 :(得分:1)

NSArray *answers = [self.questions[0] answers];  //This is the answers array of the first question
MPMediaItem *item = answers[0]; //This is that MPMediaItem you want.

答案 2 :(得分:1)

MPMediaItem *item = [[self.question[0] answers] objectAtIndex:0];