Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将大量数据从JSON拉到iOS;如何加快加载时间?_Php_Mysql_Ios_Json - Fatal编程技术网

Php 将大量数据从JSON拉到iOS;如何加快加载时间?

Php 将大量数据从JSON拉到iOS;如何加快加载时间?,php,mysql,ios,json,Php,Mysql,Ios,Json,我使用PHP文件从MySQL数据库输出JSON数据。数据库包含12000多行,我正在将所有这些数据拉到一个iOS表视图(这是一个客户列表)。有没有办法加快加载时间?现在,应用程序加载数据需要10秒的时间。我正在使用以下代码检索信息: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view f

我使用PHP文件从MySQL数据库输出JSON数据。数据库包含12000多行,我正在将所有这些数据拉到一个iOS表视图(这是一个客户列表)。有没有办法加快加载时间?现在,应用程序加载数据需要10秒的时间。我正在使用以下代码检索信息:

       - (void)viewDidLoad
        {
            [super viewDidLoad];
            // Do any additional setup after loading the view from its nib.

            [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
            NSURL *url = [NSURL URLWithString:@"URLHERE.php"];
            NSURLRequest *request = [NSURLRequest requestWithURL:url];
            [[NSURLConnection alloc] initWithRequest:request delegate:self];

            // Do any additional setup after loading the view, typically from a nib.
        }

        - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
        {
            data = [[NSMutableData alloc] init];

        }

        - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)theData
        {
            [data appendData:theData];

        }

        - (void)connectionDidFinishLoading:(NSURLConnection *)connection
        {
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

            Customers = [NSJSONSerialization JSONObjectWithData:data options:nil error:nil];
            [CustomerTableView reloadData];

        }

        - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
        {
            UIAlertView *errorView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"The download could not complete - please make sure that you're connected to 3G or Wi-Fi." delegate:nil
                                                      cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
            [errorView show];
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;


        }
        - (int)numberOfSectionsInTableView: (UITableView *)tableview

        {
            return 1;

        }

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CustomerTableIdentifier = @"CustomerCell";

        CustomerCell *cell = (CustomerCell *)[tableView dequeueReusableCellWithIdentifier:CustomerTableIdentifier];
        if (cell == nil)
        {
            NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomerCell" owner:self options:nil];
            cell = [nib objectAtIndex:0];

        }
        if (tableView == self.searchDisplayController.searchResultsTableView) {

            NSLog(@"Using the search results");

            cell.customerfname.text = [[searchResults objectAtIndex:indexPath.row] objectForKey:@"customerfname"];

            cell.customerlname.text = [[searchResults objectAtIndex:indexPath.row] objectForKey:@"customerlname"];

            cell.customeremail.text = [[searchResults objectAtIndex:indexPath.row] objectForKey:@"customeremail"];

            cell.lastupdate.text = [[searchResults objectAtIndex:indexPath.row] objectForKey:@"lastupdate"];

            cell.customerphone.text = [[searchResults objectAtIndex:indexPath.row] objectForKey:@"customerphone"];


            NSLog(@"%@", searchResults);



        } else {
            NSLog(@"Using the Full List!");

            cell.customerfname.text = [[Customers objectAtIndex:indexPath.row] objectForKey:@"customerfname"];

            cell.customerlname.text = [[Customers objectAtIndex:indexPath.row] objectForKey:@"customerlname"];

            cell.customeremail.text = [[Customers objectAtIndex:indexPath.row] objectForKey:@"customeremail"];

            cell.lastupdate.text = [[Customers objectAtIndex:indexPath.row] objectForKey:@"lastupdate"];

            cell.customerphone.text = [[Customers objectAtIndex:indexPath.row] objectForKey:@"customerphone"];


        }

        return cell;

    }
}

这方面的加载时间可能会受到从连接速度到数据库性能等诸多因素的影响。数据库表的索引是否正确?您是否使用EXPLAIN查看查询是如何运行的以及使用了哪些索引?从桌面运行查询需要多长时间?您是否尝试通过各种连接类型(wifi、4g、LTE等)从不同的位置执行此操作?哪一部分比较慢?使用仪器(Xcode的一部分)找出问题所在。如果看不到问题,就无法解决问题。@JayBlanchard我在各种连接上都试过;“一切都慢下来!”扎夫问题?我以为加载速度变慢了,因为我有太多的数据被拉取了?看看路径:1。数据库查询到php。2.php到JSON的转换。3.连接以移动数据。4.iOS中的反序列化。5.表显示时间。其中许多可以进一步分解。最大的问题是,您是否需要首先获取所有数据,或者是否有一些子集可用于部分填充表,以使其看起来使用起来更快,然后请求其他数据。