开发者

Get all object properties from delegate array

I am successfully retrieving an array from my delegate, however 开发者_StackOverflow中文版I am struggling to get all of the objects properties, so in my AppDelegate:

    arrayOne = [[NSMutableArray alloc] init];
    NSMutableArray *tempArray1 = [self myArray];
// Add names to arrayOne
    for (MyInfo *info in tempArray1) {
        [arrayOne addObject:info.name];
    }

I then retrieve this in my MainView:

    cell.textLabel.text = [delegate.currentlyUsedArray objectAtIndex:row];

This works fine, but myArray contains other properties such as: info.age and info.height — how do I get these to another textLabel? Do I have to do the same approach as above or is there a more efficeint way?


Why can't you just add info to the array.

for (MyInfo *info in tempArray1) {
    [arrayOne addObject:info];
}

and later where you are setting it.

MyInfo *info = (MyInfo*)[delegate.currentlyUsedArray objectAtIndex:row];
cell.textLabel.text = info.name;

// Other fields should also accessible directly such as info.age and info.height.


medley, You can make method of appDelegate myArray public and get your info values right from where you need it, in this case in cellForRowAtIndexPath: method.


Following Zapko's answer, your code in MainView would look like this to access the various properties of a MyInfo object in the myArray property of your delegate object:

cell.textLabel.text  = [(MyInfo *)[delegate.myArray objectAtIndex:row] name];
cell.ageLabel.text   = [(MyInfo *)[delegate.myArray objectAtIndex:row] age];
cell.heigtLabel.text = [(MyInfo *)[delegate.myArray objectAtIndex:row] height];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜