Iphone 从委托数组获取所有对象属性
我正在成功地从委托中检索数组,但是我正在努力获取所有对象属性,因此在我的Iphone 从委托数组获取所有对象属性,iphone,arrays,delegates,tableview,Iphone,Arrays,Delegates,Tableview,我正在成功地从委托中检索数组,但是我正在努力获取所有对象属性,因此在我的AppDelegate中: arrayOne = [[NSMutableArray alloc] init]; NSMutableArray *tempArray1 = [self myArray]; // Add names to arrayOne for (MyInfo *info in tempArray1) { [arrayOne addObject:info.name];
AppDelegate
中:
arrayOne = [[NSMutableArray alloc] init];
NSMutableArray *tempArray1 = [self myArray];
// Add names to arrayOne
for (MyInfo *info in tempArray1) {
[arrayOne addObject:info.name];
}
然后,我在我的main视图中检索它:
cell.textLabel.text = [delegate.currentlyUsedArray objectAtIndex:row];
这很好,但是myArray
包含其他属性,例如:info.age
和info.height
-如何将这些属性传递到另一个textlab
?我必须采用与上述相同的方法还是有更有效的方法?混合泳,
您可以将appDelegatemyArray
的方法公开,并从您需要的位置获取信息值,在本例中是在cellForRowAtIndexPath:
方法中。为什么不能将info
添加到数组中呢
for (MyInfo *info in tempArray1) {
[arrayOne addObject:info];
}
稍后在哪里设置它
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.
按照Zapko的回答,MainView中的代码如下所示,以访问代理对象的myArray属性中MyInfo对象的各种属性:
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];
嗨,扎普科,谢谢你的回复,听起来不错。。。因此,我在AppDelegate
中公开了myArray
,那么我还需要在MainView中公开它吗?然后在我的cellforrowatinexpath
中,我应该能够获得myArray.info
和myArray.age
等。。。?谢谢你的时间!还有,在cellforrowatinexpath
中会是什么样子?它是否类似于:cell.textlab.text=[delegate.myArray.info.name objectAtIndex:row]代码>?再次感谢!是的,我想它看起来像:cell.textlab.text=((MyInfo*)[delegate.myArray objectAtIndex.row])。name
太棒了!非常感谢!很好。嗨,谢谢你的回答!我选择了Deepak的解决方案,但你的回答也很有帮助,就像Zapko的。。。如果可以,我会投票给你们所有人!!!