gpt4 book ai didi

ios - objective-c : Use a array to point to another array

转载 作者:行者123 更新时间:2023-11-29 12:33:58 24 4
gpt4 key购买 nike

我有两个可变数组。“friendsArray”包含整个操作系统用户列表,“inviteIndex”包含其中一些用户的索引 (indexPath.row)(使用 uiswitch 按钮进入表格列表)。

我将 inviteIndex 数组填充为:

[inviteIndex addObject:[NSNumber numberWithInteger:indexPath.row]];

为了只选择我做的用户:

  for (int i =0; i< [inviteIndex count]; i++) {

MyElement *friend =[friendsArray objectAtIndex:[inviteIndex objectAtIndex:i] ];

NSLog(@"BUTTON PRESSED %@", friend.friendId);

}

但应用崩溃并显示消息:

[__NSArrayM objectAtIndex:]: index 400931632 beyond bounds [0 .. 4]'

我试过
MyElement *friend =[friendsArray objectAtIndex:(NSInteger)[inviteIndex objectAtIndex:i] ]; 结果相同。

有什么帮助吗?提前致谢。

最佳答案

[inviteIndex objectAtIndex:i] 将返回一个 NSNumber 对象。您需要 NSNumber 对象中的 NSInteger:

for (int i =0; i< [inviteIndex count]; i++) {

NSInteger index = [[inviteIndex objectAtIndex:i] integerValue];
MyElement *friend =[friendsArray objectAtIndex:index];

NSLog(@"BUTTON PRESSED %@", friend.friendId);

}

关于ios - objective-c : Use a array to point to another array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26863235/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com