[英]Pulling an NSArray out of a NSMutableArray
I have an NSMutableArray which is storing a list of other arrays. 我有一个NSMutableArray存储其他数组的列表。 And when i run the code. 当我运行代码。
NSLog(@"%@",[[appDelegate teamRoster]objectAtIndex:[indexPath.row]class])
It returns and tells me that i am looking at an Array, 它返回并告诉我,我正在看一个数组,
however when i try to do the following 但是当我尝试做以下事情时
[selectedRowerView tempArray] = [[appDelegate teamRoster]objectAtIndex:[indexPath.row]];
The program errors out. 程序出错了。 Anyone have any ideas why this might be happening? 任何人都有任何想法为什么会发生这种情况?
You have to understand that [selectedRowerView tempArray]
is actually a command / message that is being sent. 您必须了解[selectedRowerView tempArray]
实际上是一个正在发送的命令/消息。 In C++ equivalent, you are calling selectedRowerView->tempArray() = ...
. 在C ++等价物中,您调用selectedRowerView->tempArray() = ...
Which doesn't make logical sense because you cannot make an assignment to a function. 这没有逻辑意义,因为你无法对一个函数进行赋值。
What you're trying to do is set the tempArray. 你要做的是设置tempArray。 If you have the proper setters/getters set-up, you can just run: selectedRowerView.tempArray = ...;
如果你有适当的setter / getters设置,你可以运行: selectedRowerView.tempArray = ...;
Just make sure that tempArray has a @property
and is @synthesize
'd. 只要确保tempArray有一个@property
,是@synthesize
“d。
How about this? 这个怎么样?
selectedRowerView.tempArray = [[appDelegate teamRoster]objectAtIndex:[indexPath.row]];
…assuming that tempArray
is a synthesized property à la ...假设tempArray
是一个综合属性àla
@property (nonatomic, readwrite, retain) NSArray *tempArray;
@synthesize tempArray;
Clarification: 澄清:
selectedRowerView.tempArray = …;
gets internally processed to 内部处理到
[selectedRowerView setTempArray:…];
which is a setter method . 这是一种二传手法 。
While 而
selectedRowerView.tempArray;
gets internally processed to 内部处理到
[selectedRowerView tempArray];
which is a getter method . 这是一种吸气方法 。
Subtle but important difference. 微妙但重要的区别。
The meaning of foo.bar
depends on the very context (enclosing expression) it is used in. foo.bar
的含义取决于它所使用的上下文(封闭表达式)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.