开发者

UITableViewController not highlighting cell when it's selected

开发者 https://www.devze.com 2023-02-04 19:16 出处:网络
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 lo

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 untl开发者_Python百科i previous request is done).

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


Set the selectionStyle of the UITableViewCell's to 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: e.g. 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'
0

精彩评论

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