iPhone4s 7.0.3-4 TableView 数据越界 解决方案

在实现一个TableView时需要实现两个代理方法<UITableViewDataSource,UITableViewDelegate>实现

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

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

  正常情况下系统会默认先执行- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;方法,再执行- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath,这样是没有问题的。

   但是在有些没有升级的到iOS7.1的用户来说,例如4s 用户只升到了7.0.3或7.0.4,当你改变TableView的Frame的时候,系统不会执行- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; 方法,导致数组越界。

   所以为了保持代码的健壮性,应该在dataArray改变时,先执行TableView的Reload方法,再去改变TableView的Frame。就不会出现数组越界的问题!

posted @ 2014-11-12 10:45  i0ject  阅读(306)  评论(0编辑  收藏  举报