簡體   English   中英

如何通過 indexPath.row 或僅行號而不是 indexpath 獲得 uitableViewCell?

[英]How can I get a uitableViewCell by indexPath.row or only row number instead of indexpath?

我們可以像這樣輕松地從 indexPath 獲取 UITableViewCell:

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

但是我只有行號而不是索引路徑,我正在使用此代碼來獲取單元格。

NSArray *visible       = [self.tableView indexPathsForVisibleRows];
NSIndexPath *indexpath = (NSIndexPath*)[visible objectAtIndex:MyRowNumber];
UITableViewCell *tablecell = [self.tableView cellForRowAtIndexPath:indexpath];

告訴我這是否是一個好的方法,如果不是,哪個是。

您可以使用行號創建一個新的NSIndexPath (假設您的表只有一個部分)。

NSIndexPath *indexPath= [NSIndexPath indexPathForRow:yourRowNumber inSection:0];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM