Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView: How to get all rows for a particular section?

What I want?
I want to add radio button functionality where a user in particular section can only select one row

enter image description here

How am I doing it?
I added UISwitch and based on what row user click I would like to do the following

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 1 || indexPath.section == 2) {

      // disable all the rows of this section except indexPath.row          
    }
}

Where am I stuck?

How do I get all the rows for a given section in UITableView?

P.S: I am a week old to iOS and learning, so bear with me if this is a stupid question

like image 731
daydreamer Avatar asked Jun 24 '14 19:06

daydreamer


1 Answers

Use[tableView cellForRowAtIndexPath:(NSIndexPath *)]

for (int i = 0; i < [self.tableView numberOfRowsInSection:indexPath.section]; i++) {
    if (i != indexPath.row) {
        UITableViewCell* cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:indexPath.section]];
        //Do your stuff
    }
}
like image 55
Soul Clinic Avatar answered Sep 28 '22 04:09

Soul Clinic