如何防止第二次单击UITableView [英] How to prevent clicking UITableView second time

查看:47
本文介绍了如何防止第二次单击UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序在tableView:didSelectRowAtIndexPath中调用一个块,并在该块中提供一个视图控制器.如果在第一次单击时第二次单击该单元格,它将崩溃.如何防止再次单击该单元格?

My app calls a block in tableView:didSelectRowAtIndexPath and in the block it presents a view controller. If I click the cell second time when the first click is in progress, it crashes. How can I prevent the cell to be clicked second time?

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


    [dataController fetchAlbum:item
         success:^(Album *album) {
            ...
            ...

            [self presentViewController:photoViewController animated:YES completion:nil];


               }];

推荐答案

didSelectRow 的开头,关闭表上的用户交互.

At the beginning of didSelectRow, turn off user interaction on your table.

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    tableView.userInteractionEnabled = NO;
    ...

您可能希望稍后在 fetchAlbum 完成时将其重新打开(在主线程上执行此操作),以便如果用户返回此视图(或获取失败),则他们可以再次与表格互动.

You may want to turn it back on later in the completion of fetchAlbum (Do this on the main thread) so that if the user comes back to this view (or the fetch fails), they can interact with the table again.

这篇关于如何防止第二次单击UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆