访问多维数组中的对象,Obj-c
我有一个包含其他数组的数组,但无法让它工作!我试图从子数组中提取字符串值,我可以首先访问第一个子数组,没有问题,但是当我尝试将标签更改为第二个数组中的对象时,我的程序崩溃了,我知道我应该如何处理这个问题吗?
int count = 0; // variable to access the required sub array
NSArray* myArray; // array holding other arrays
UILabel* mylabel; // label to display my string values from the array s
-(void) setLabel
{
NSArray* subArray = [myArray objectAtIndex: count];
[myLabel setText:[subArray objectAtIndex:1]]; // this works fine
}
-(void) changeLabelToNextArray
{
count ++
[self setLabel]; //program crashes here when try to load label from next array
}
I have an array holding other arrays, but cant get this to work!! IM trying to pull string values from subArrays I can access first the first subarray no problem but then when i try changing the label to the object in second array my prog crashes anyidea on how i should approach this?
int count = 0; // variable to access the required sub array
NSArray* myArray; // array holding other arrays
UILabel* mylabel; // label to display my string values from the array s
-(void) setLabel
{
NSArray* subArray = [myArray objectAtIndex: count];
[myLabel setText:[subArray objectAtIndex:1]]; // this works fine
}
-(void) changeLabelToNextArray
{
count ++
[self setLabel]; //program crashes here when try to load label from next array
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你为什么要这样做?
则这将崩溃
我认为有关数组结构的更多信息将有助于给出更好的答案问题是什么。
编辑(基于下面的评论)
试试这个:
现在,每当您调用 setLabel 时,只要 5 个子数组中的每个子数组中确实有 5 个字符串,所有 5 个标签上的文本都应该发生变化。
Why are you doing this?
This will crash if
I think some more information on how your arrays are structured would help give a better answer to what the problem is.
EDIT (Based on comments below)
Try this:
Now whenever you call setLabel, the text should change on all 5 of your labels provided you do indeed have 5 strings in each of the 5 subarrays.
也许你可以尝试使用 C 数组:
Maybe you can try to use C array :