简体   繁体   中英

UITableViewController not highlighting cell when it's selected

Hi I've got simple question which I don't know how to answer. In my app I've got UITableViewController with cells. When I select one item (cell) it's getting higlighted and in other thread I'm loading chunk of data to display to the user (after load is done new VC is pushed). When doing it with thread user still can interact with application like, going back to other NavController and I do want that to happen. What I don't want to happen is that when loading isn't complete user can select other cell in table and it get's highlted. How I can prevent that (only highlit, I'm checking if there was a previous request so I'm not putting another thread untli previous request is done).

So basicly my question is, how can you foribd user from interacting with table view controller?

UITableViewCellselectionStyle设置为UITableViewCellSelectionStyleNone

You can use the following to check if row can be selected:

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {

         if (rowSelected) {
              return nil;
         }

         return indexPath; 
    }

So, you only select it if no row is selected. In your didSelectRowAtIndexPath method:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

rowSelected = YES;
// call method that is going to do something and mark rowSelected = NO; 
}

You can deselect the row by using

[[tableView cellForRowAtIndexPath:indexPath] setSelected:NO animated:YES];

There is a risk that your users will be confused. A highlight is not enough. There should be very clear visual feedback that a network opperation is ongoing and that different rules apply.

  • either push the details view immediately after the user selected a row and show an activity indicator in there.
  • or give the whole table view a different look while loading data for the selected row: eg Show activity indicator in the selected row & hide the disclosure chevrons in all the other. While doing that, you can set the selection style to 'none'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM