我有自定义单元格的表格视图。单元格具有图像视图,标签和进度视图。我想实现的是根据发生的事件更新特定单元格中的进度视图。我的想法是通过事件中的名称标签来查找单元格,然后更新进度视图。这可能不是一种有效的方式,但我想不出其他方式。其他想法也表示赞赏。提前致谢。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