Bau*_*i89 2 uitableview nsmutablearray ios indexoutofboundsexception
在我的应用程序中,我尝试从url加载内容,将它们存储在一个可变数组中并在表视图中显示它们.但是我无法让它工作,因为每次运行应用程序时都会出现此错误:
*** 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
Run Code Online (Sandbox Code Playgroud)
我创建了应该在viewDidLoad中填充表格的数组:
_videos = [[NSMutableArray alloc] init];
Run Code Online (Sandbox Code Playgroud)
然后我连接到url并解析收到的xml数据.这样就可以了.当打开某个标签时,我创建了我的视频对象,在用数据填充之后,我将这些对象添加到我的数组中:
[_videos addObject:currentVideo];
Run Code Online (Sandbox Code Playgroud)
这似乎也有效,因为它返回正确数量的视频
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _videos.count;
}
Run Code Online (Sandbox Code Playgroud)
叫做.但在此之后,应用程序崩溃了,我甚至没有达到我尝试填充表格视图的程度.该函数如下所示:
- (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;
}
Run Code Online (Sandbox Code Playgroud)
怎么了?
提前致谢
小智 5
-[__NSArrayI objectAtIndex:]: index 4 beyond bounds [0 .. 1]'尝试呈现模式故事板时,我有相同的错误签名,表视图有两个(从五个更新)静态表格单元格部分.直到我删除了视图中不再需要的三个表格单元格部分才出现此错误.在模态演示文稿之前检查我的所有objectAtIndex引用两天之后,我决定查看UITableViewController子类代码本身.我找到了这个:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//#warning Potentially incomplete method implementation.
// Return the number of sections.
return 5;
}
Run Code Online (Sandbox Code Playgroud)
然后灯泡熄灭了.的index 4被称为相关的部分的我的表视图数目和所结合的[0 .. 1]称为我的目前的两层表单元格的部分.更新该return值以匹配Storyboard表视图中当前表格单元格部分的数量解决了该问题.
| 归档时间: |
|
| 查看次数: |
17769 次 |
| 最近记录: |