繁体   English   中英

使用insertRowsAtIndexPaths时,索引超出空数组的范围

[英]index beyond bounds for empty array when using insertRowsAtIndexPaths

最初没有。 的部分= 0,没有。 Section = 0中的行数。 有数据时,否。 的部分更改为1且没有。 节中的行继续递增1。

NSArray *indexPathArray=[NSArray arrayWithObject:rowSectionIndexPath];  
[tableView beginUpdates];
[tableView insertRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationFade]; 
[tableView endUpdates];

我试图使用上面的代码在表中插入行。 但是收到错误-[NSMutableArray objectAtIndex:]:索引1超出了空数组的范围。

我从中开始将Data插入行的行和节的值分别为row = 1和section = 1; row = 2和section = 1; ....等。

考虑到我已经使用了所有必需的方法numberOfSectionsInTableView,numberOfRowsInSection,cellForRowAtIndexPath和heightForRowAtIndexPath,因此我在代码中缺少什么。

尝试这个。 它可能会帮助您。

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
            return 1;
    }

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


      return [displayWineList count];//pass your array count
    }

这样尝试..,

   - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView  
     {            
       return 1;    
     } 

   - (NSInteger)tableView:(UITableView *)tableView
      numberOfRowsInSection:(NSInteger)section   
     {         
       return [yourArray count];
     }

我从中开始将Data插入行的行和节的值分别为row = 1和section = 1; row = 2和section = 1; ....等。

您是否尝试从第0行开始? (也许您做到了,但我不是英国人,您问题的第一部分使我感到困惑)

因为如果您从一个空表开始,则在尝试填充1之前需要填充0。

请写出

[tableview reloadData]

要么

[tableView reloadSections:[NSIndexSet indexSetWithIndex:0]withRowAnimation:UITableViewRowAnimationRight];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM