我有自定義單元格的表格視圖。單元格具有圖像視圖,標籤和進度視圖。我想實現的是根據發生的事件更新特定單元格中的進度視圖。我的想法是通過事件中的名稱標籤來查找單元格,然後更新進度視圖。這可能不是一種有效的方式,但我想不出其他方式。其他想法也表示讚賞。提前致謝。iOS Table View Finding A Cell
回答
您可以使用NSDictionary和名稱作爲鍵,NSIndexPath作爲對象。然後,可以使用字典中的名稱查找給定單元格的索引路徑。
UITableView
有一個'cellForRowAtIndexPath:`方法,它應該爲您提供特定行的單元格。
即像
// Get visible cell for data item
NSInteger row = [myArrayOfThings indexOfObject:thing];
NSIndexPath *inedexPath = [NSIndexPath alloc] initWithRow:row section:0];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indeexPath];
// Update cell here ...
...
免責聲明:代碼從內存類型 - 你可能要看看文檔的一些方法和名字:)
的更多更好的辦法是用標籤,
你可以給每一個小區的唯一的標籤,並通過這種方法訪問細胞
//method of UIView(UIViewHierarchy)
- (UIView *)viewWithTag:(NSInteger)tag;
// can be used like this
UITableViewCell *cell = (UITableViewCell*)[tableView viewwithtag:tag];
只有在表格視圖沒有回收單元格的情況下,這種行爲纔有效嗎? – deanWombourne
好吧,如果標識符對每個單元格都是唯一的,那麼它可以工作。 –
如果你有100行,但只顯示7個再生細胞如何有100個唯一標識符 - 細胞將被回收!您是否計劃在每次顯示單元時重新貼上單元格? – deanWombourne
- 1. iOS Table View Cell not resizing
- 2. Custom Table View Cell
- 3. JavaFX Table view Cell Reuse
- 4. NSTableView Table View Cell Memory問題
- 5. ui table view cell reorder * without * shadow
- 6. Xamarin Table View Crash
- 7. Javascript select table cell
- 8. WordML:Set Table Cell Width
- 9. 爲什麼我的Table View Cell無法顯示?
- 10. ios swift table half a screen
- 11. iPhone Table View Section Headers
- 12. 如何在Swift中擴展Table View Cell的高度?
- 13. JavaFX Table/TreeTable Cell Overflow
- 14. Sql Table dynamic cell typ
- 15. Swift 2:Table view cellForRowAtIndexPath - BAD_EXEC
- 16. Table view中的不同圖像View?
- 17. 如何進行顯示:table-cell div cover毗連table-cell divs?
- 18. iOS - 爲什麼table view不顯示?
- 19. table-cell> img extra 4px space
- 20. iphone table view
- 21. Grid Table VIew
- 22. javascript table cell not update and I have a row index
- 23. animate div width style = table-cell
- 24. CSS display:table-cell with div inside table
- 25. javascript table row cell selected dropdown value
- 26. JavaFX Table Cell格式化
- 27. XSL FO Table Cell Wrap方向
- 28. Fieldset不支持display:table/table-cell
- 29. App \ View \ Cell CakePHP3分頁?
- 30. Array,not refheshing table view
字典效果不錯:) – user1061894