我目前在xcode中开发新手,我想知道如何访问另一个对象内部的对象(即车对象内部的汽车对象)的字段。Objective-C:访问对象内的对象字段
对于我的cellForRowAtIndexPath方法,我试图访问位于我的Admission类中的Patient Class中的字段。我有一个数组[myList],它拥有准入对象,并且在准入对象中,我有病人对象。
这里就是我有一个问题的代码,我的cellForRowAtIndexPath方法中:
static NSString *CellIdentifier = @"SimpleCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [[admList objectAtIndex:row]admPatName];
return cell;
}
问题是下面这行:
cell.textLabel.text = [[myList objectAtIndex:row]??];
在??区域,我无法弄清楚该领域的正确参考。
有什么建议吗?
感谢 JR
您能否发布信息您的患者类从.h文件? – dasblinkenlight 2012-02-11 01:38:22
Objective-C对象不能直接访问属于另一个对象的字段。 (如在公共C++成员中)。相反,您必须向另一个[otherObj getFoo]或另一个属性otherObj.foo发送消息。 – seand 2012-02-11 01:43:13