Activity Indicators when pushing next view - didSelectRowAtIndexPath

后端 未结 1 1218
醉酒成梦
醉酒成梦 2021-01-03 10:16

I can successfully push only next view in my iPhone app. However, cause the next view retrieves data to populate the UITableViews, sometimes waiting time could

相关标签:
1条回答
  • 2021-01-03 10:36

    You can implement this in didSelectRowAtIndexPath: method itself.

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleWhiteLarge];
    cell.accessoryView = spinner;
    [spinner startAnimating];
    [spinner release];
    

    This will show the activity indicator at the right side of the cell which will make the user feel that something is loading.

    Edit: If you set the accessoryView and write the loading code in the same method, the UI will get updated only when all the operations over. A workaround for this is to just set the activityIndicator in the didSelectRowAtIndexPath: method and call the view controller pushing code with some delay.

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {  
    
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleWhiteLarge];
        cell.accessoryView = spinner;
        [spinner startAnimating];
        [spinner release];
    
        [self performSelector:@selector(pushDetailView:) withObject:tableView afterDelay:0.1];
    }
    
    - (void)pushDetailView:(UITableView *)tableView {
    
        // Push the detail view here
    }
    
    0 讨论(0)
提交回复
热议问题