代码之家  ›  专栏  ›  技术社区  ›  ingh.am

在iPhone上更新表格单元格中的值

  •  5
  • ingh.am  · 技术社区  · 14 年前

    如果在iPhone应用程序中设置了一个包含许多行的tableView,如何只更新其中一行?我知道它们在进入视图时会手动刷新,但我希望推出一个更新,以便计时器倒计时。

    谢谢

    3 回复  |  直到 14 年前
        1
  •  15
  •   ingh.am    14 年前

    称之为:

    NSIndexPath *a = [NSIndexPath indexPathForRow:0 inSection:0]; // I wanted to update this cell specifically
    CustomTableViewCell *c = (CustomTableViewCell *)[theTableView cellForRowAtIndexPath:a];
    

    [c nowPlayingTrack].text = ...
    

    希望有一天这能帮助别人!

    我不知道为什么,但是仅仅调用tableView上的reloadData会因为自定义标签而导致运行时错误。:(

        2
  •  3
  •   burki    14 年前

    - (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
    

    typedef enum {
       UITableViewRowAnimationFade,
       UITableViewRowAnimationRight,
       UITableViewRowAnimationLeft,
       UITableViewRowAnimationTop,
       UITableViewRowAnimationBottom,
       UITableViewRowAnimationNone,
       UITableViewRowAnimationMiddle
    }
    

    如果不知道indexPath,可以通过调用

    + (NSIndexPath *)indexPathForRow:(NSUInteger)row inSection:(NSUInteger)section
    
        3
  •  1
  •   Dutchie432    14 年前

    我假设您正在使用某种类型的自定义UITableViewCell。。。。

    您可以直接访问它(请原谅我缺乏实际的iphone语法。。已经好几个月了)

    你也许可以直接访问它,但我在这样做时遇到了问题。

    [[[myUITableView cells] itemAtIndex:14] setTimerValue:WHATEVER];