2016-11-06 8 views
0

私はUITableViewを持っています。これはJSON文字列のデータで埋められます。 pastebinのコードをご覧ください。その時点でreloadRowsAtIndexPathsがJSON imageUrlsでクラッシュする

dispatch_async(dispatch_get_main_queue(), {() -> Void in 
       self.tableView.beginUpdates() 
       self.tableView.reloadRowsAtIndexPaths(
        [indexPath], 
        withRowAnimation: .Fade) 
       self.tableView.endUpdates() 
      }) 

、それが失敗しました。私はreloadRowsAtIndexPathsを削除する場合、それは動作しますが、私はあなたがスクロールしたり、デバイスを回転させる場合を除いて行を更新しない、

2016-11-06 16:32:06.579471 SO-33975355[4872:1389586] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete row 7 from section 0 which only contains 0 rows before the update' 

は、私は、次のメッセージが表示されます。もちろん私はそれを直接更新したい。

私はそれが速くなることと関係があると思いますか?しかし、私はthis from the exampleを変更して以来、私は完全に無知です。 (この例ではJSONではなくwikipediaのURLを使用できます)

誰かが助けてくれたら嬉しいです。

答えて

0

self.tableView.reloadRowsAtIndexPathsを呼び出す前に、tableViewが既に作成されており、dataSourceを正しく設定していることを確認してください。また、2つのデータソースは、あなたのtableView(self.tableView.reloadRowsAtIndexPathsの前)に呼び出される必要があります。

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) { 
     //Please return the maximum number of rows you are expecting from JSON. This is required because when you do reloadRowsAtIndexPaths, it should know that row index already exist 
    } 
     func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     //Return cell 
} 
0

誤差はかなり明確です:

理由:「のみ更新前の0行を含むセクション0から7行を削除しようと」

あなたがリロードしようとしていますセクション7の最初の行ですが、セクション7はゼロの行を持つため、最初の行はありません。

あなたのデータモデルをチェックしてください。

0

これを試してみてください:

self.tableView.beginUpdates() 
self.tableView.reloadRowsAtIndexPaths(
        [indexPath], 
        withRowAnimation: .Fade) 
self.tableView.endUpdates() 
関連する問題