Created
March 24, 2017 05:04
-
-
Save fuzz6001/94ab2586c7c8347df116b95958c776cc to your computer and use it in GitHub Desktop.
reloadしたときのindexPathsForVisibleRowsの全てがwillDisplayCellを実行したらreload完了とみなすテスト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
reloadしたときのindexPathsForVisibleRowsの全てがwillDisplayCellを実行したらreload完了とみなすテスト | |
以下の記事に対応しています。 | |
[reloadData処理後に処理を行いたい] | |
http://qiita.com/ponkichi4/items/d5d46556773a6bc98f9c | |
Swift2です | |
*/ | |
@IBOutlet weak var table: UITableView! | |
var indexPathsForVisibleRows: [NSIndexPath]? //保存用 | |
(中略) | |
//ボタン押したらreload | |
@IBAction func pushedButton(sender: UIButton) { | |
NSLog("pushed") | |
//保存 | |
indexPathsForVisibleRows = table.indexPathsForVisibleRows | |
//表示してみる | |
indexPathsForVisibleRows?.forEach { | |
NSLog("[indexPathsForVisibleRows] %@", $0) | |
} | |
NSLog("execute reload!") | |
table.reloadData() | |
//ponkichi4さんのアイデア | |
NSOperationQueue.mainQueue().addOperationWithBlock { | |
NSLog("[addOperationWithBlock] all reloaded") | |
} | |
NSLog("executed reload") | |
} | |
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { | |
if let index = indexPathsForVisibleRows?.indexOf(indexPath) { | |
//保存用Arrayから削除 | |
indexPathsForVisibleRows?.removeAtIndex(index) | |
NSLog("[willDisplayCell] \(indexPath)") | |
if indexPathsForVisibleRows?.count == 0 { | |
//全て無くなったので完了!! | |
NSLog("all reloaded") | |
} | |
} else { | |
//reload時以外はここに来る | |
NSLog("unknown cell") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
縦→横回転後でも大丈夫。