开发者

TableView Cell selection problem? [closed]

开发者_运维问答 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I want to implement tableview in which by default one cell is selected for a particular value and we can select the other cell and the tick mark appear on it. At a single time select a particular cell for particular value.

I want to implement this for the selection of the countries through which we match the particular country API for parsing.

Thanks in advance.


Unless this is an iPad app with a tableview as the left pane, leaving a UITableView with a selected UITableViewCell is against Apple's human interface guidelines. Apple prefers that you use just the tick mark (set the UITableViewCell accessory type to UITableViewCellAccessoryCheckmark) to indicate that the particular row is selected.

Here's some code to get you started:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  NSArray *visibleCells = [tableView visibleCells];
  // Remove checkmark from all visible cells
  for (UITableViewCell *aCell in visibleCells) {
    aCell.accessoryType = UITableViewCellAccessoryNone;
  }
  // Now add the tick mark to the selected cell
  UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
  selectedCell.accessoryType = UITableViewCellAccessoryCheckmark;
  [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

Don't forget to set the appropriate accessoryType in your - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath implementation too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜