LoginSignup
3
3

More than 5 years have passed since last update.

UITableViewの更新について

Last updated at Posted at 2015-03-19

一覧のうち、一つだけをチェックするようなUITableViewのCheckmarkの更新をする際に、今までは選択したindexを変数として保持し、その都度TableをreloadDataしていたので
どうも動きがダサいなぁと思っていましたが、普通は多分こんな風にやるのですね。今更ですが。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    for (int i = 0; i < [tableView numberOfRowsInSection:0]; ++i)
    {
        UITableViewCell *c = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
        c.accessoryType = UITableViewCellAccessoryNone;
        if (i == indexPath.row) {
            c.accessoryType = UITableViewCellAccessoryCheckmark;
        }
    }
}
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3