两个ViewController Segue之间的弹出/警报

时间:2014-05-02 21:44:45

标签: ios uialertview segue

我有两个ViewController并使用(tableview click)seque来打开第二个ViewController。 我的问题是,第二视图控制器加载了大量数据。因此,切换之间的时间是<> 10秒。在这10秒内,App冻结了。多数民众赞成,但我怎么能插入像“请等待......”这样的“弹出”或“警报”消息。我已经为Popups和Alerts测试了很多教程,但是当SecondView Controller完全加载时,Popup / Alter只显示。我将显示消息BEVOR,SecondViewController被编译加载。

示例:

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

        // IF i set here the ALERT, the Alter was only show, when the Second View Controller is complete loaded!

        NSDictionary *rowVals = (NSDictionary *) [SearchNSMutableArray objectAtIndex:indexPath.row];

        [self performSegueWithIdentifier:@"Foo" sender:self];


    }

    -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {

        if ([[segue identifier] isEqualToString:@"Foo"]) {

            // Get indexpath from Tableview;
            NSIndexPath *indexPath = [self.SearchUITableView indexPathForSelectedRow];

            // Get Data from Array;
            NSDictionary *rowVals = (NSDictionary *) [self.SearchNSMutableArray objectAtIndex:indexPath.row];

            // Destination View;
            [MySecondViewController alloc];
            MySecondViewController *MyView = (MySecondViewController *)segue.destinationViewController;

        }
}

2 个答案:

答案 0 :(得分:0)

您正尝试使用错误的解决方案解决问题。该解决方案同样糟糕,因为弹出窗口也会冻结10秒钟。如果添加更多数据并需要30秒或10分钟,该怎么办?您是否希望您的用户看到他们可以在10分钟内解雇的对话?

您是从互联网上获取数据吗?如果是这样,您需要在后台异步获取数据。

如果您从磁盘加载它,那么加载太多可能会在一个屏幕上显示,您只需加载一小部分,如果仍然需要很长时间你需要异步加载它的时间。

  • 更新 -

您的应用程序应该有一个模型类,负责从Internet获取数据。 Google模型视图控制器可获取有关模型的一些背景信息。

只要应用程序启动,模型就可以开始下载需要在后台删除的数据(这个主题太大,无法在此处回答如何操作)。

View控制器可以在下载数据时启动,并且可以在等待时显示旋转活动指示轮或进度条或对话框等。重要的是GUI不会冻结。

当模型下载了数据时,它需要告诉视图控制器数据现在可用,它可以使用NSNotification中心进行。

你有很多需要调查和学习的事情,如果没有GUI冻结它需要正确完成,没有捷径,你需要学习很多东西。

答案 1 :(得分:0)

@马丁,

我找到了解决方案:

// Send the Request;
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue]
                       completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {

因此请求是异步的。感谢您的回答。伟大的+1

相关问题