How to find the number of cells in the section in which the selected cell is located through the method tableView: didSelectRowAtIndexPath :?

    2 answers 2

    Pull - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section at the datasource (usually the same class), the section number is listed in IndexPath

    • And how to change Accessory for 3 cells in 5 sections? - 97mik
    • one
      something like NSIndexPath * indexPath = [NSIndexPath indexPathForRow: 3 inSection: 5]; UITableViewCell * cell = [self.tableView cellForRowAtIndexPath: indexPath]; cell.accessoryView = ... - aknew

    You should NOT look at the number of sections. cells in them and in general cells. This is all a view.

    You have to look at your model to understand this, and generally understand what and how is it with you. For example, if you have an array where you take data, see the number of items in it, or if you have each section in its array, look at them.

    The answer is essentially:

    [self.tableView numberOfRowsInSection: 1];

    Where 1 is the section number.