gpt4 book ai didi

iOS 错误 : [__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .。 0]

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:59:36 24 4
gpt4 key购买 nike

在我的应用程序中,我尝试从 url 加载内容,将它们存储在可变数组中并在 TableView 中显示它们。但我无法让它工作,因为每次我运行该应用程序时都会出现此错误:

*** Terminating app due to uncaught exception 'NSRangeException', 
reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
*** First throw call stack:
(0x34dd088f 0x36d9e259 0x34d2823d 0x316e562f 0x315f09a9 0x313c0c5d 0x313c1b95 0x313c1ae7
0x313c16c3 0xa5cfb 0x33623ec7 0x35387a09 0x35390051 0x33622965 0xa4dc1 0x313a8e33
0x313cd629 0x31391d7d 0x314544dd 0x3139a55d 0x3139a579 0x3139a40b 0x3139a3e7 0x313a8015
0x313a1985 0x3136fc6b 0x3136f70f 0x3136f0e3 0x3439222b 0x34da4523 0x34da44c5 0x34da3313
0x34d264a5 0x34d2636d 0x313a0a13 0x3139de7d 0xa4745 0xa46dc)
terminate called throwing an exception

我创建了一个数组来填充我的 viewDidLoad 中的表:

_videos = [[NSMutableArray alloc] init];

然后我连接到 url 并解析接收到的 xml 数据。这就像它应该的那样工作。当某个标签被打开时,我创建我的视频对象,并在用数据填充它们之后,我将这些对象添加到我的数组中:

[_videos addObject:currentVideo];

这似乎也有效,因为它在以下情况下返回正确数量的视频

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

return _videos.count;
}

被调用。但在这一点之后,应用程序崩溃了,我什至没有达到尝试填充表格 View 的程度。该函数如下所示:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

Video *curVideo = [_videos objectAtIndex:indexPath.row];

static NSString *CellIdentifier = @"CustomCell";

CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil)
cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];

cell.titleLabel.text = [curVideo title];
cell.descLabel.text = [curVideo desc];

return cell;
}

哪里做错了?

提前致谢

最佳答案

我有相同的错误签名 -[__NSArrayI objectAtIndex:]: index 4 beyond bounds [0 .. 1]' 当我试图呈现模态 Storyboard时, TableView 有两个(从五个更新) 静态表格单元格部分。直到我删除了 View 中不再需要的三个表格单元格部分后,才出现此错误。在花了两天时间详细检查了模态表示之前的所有 objectAtIndex 引用之后,我决定查看 UITableViewController 子类代码本身。我发现了这个:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//#warning Potentially incomplete method implementation.
// Return the number of sections.
return 5;
}

然后灯泡熄灭了。被引用的 index 4 与我的 TableView 部分数相关,[0 .. 1] 的边界引用我当前的两个表单元格部分。更新 return 值以匹配 Storyboard 表格 View 中当前表格单元格部分的数量解决了这个问题。

关于iOS 错误 : [__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .。 0],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12641051/

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