iOS 7使用UIPickerView缓慢打开UITableViewController [英] iOS 7 slow to open UITableViewController with UIPickerView

查看:76
本文介绍了iOS 7使用UIPickerView缓慢打开UITableViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相应于这个问题和KyleC的答案,我实施了一个 UITableViewController 其中有许多行依赖于从Core Data中获取。每一行都显示一个简单的 NSString (获取的对象的名称),并隐藏 UIPickerView

Accordingly to this question and the kind answer of KyleC I've implemented a UITableViewController which has many rows relying on a fetch from Core Data. Every row display a simple NSString (name of the object fetched) and has an UIPickerView hidden.

问题是,当我点击前一个 UITableViewController 中的行打开 UITableViewController时,这是绝对明显的。 有了选择器视图,segue转换有一些延迟。

The issue is that it's absolutely evident that when I tap the row in the previous UITableViewController that opens the UITableViewController with picker views there's some delay in the segue transition.

我知道这是因为之前的控制器(他们甚至执行核心数据请求)在转换过程中并不是那么慢。

I know this because the previous controllers (they even perform Core Data requests) are not so slow in the transition.

-

一些 UIPickerView s可以使转换变得如此缓慢而且非常丑陋吗?
我应该在哪种模式下使用工具来了解哪些是慢慢的?

Can some UIPickerViews make the transition so slow and pretty ugly? In which mode should I use Instruments to understand which is the slowly-guilty?

更重要的是:如果缓慢来自<$ c的数字$ c> UIPickerView 我该如何优化呢?

More important: if the slowness is derived from the numbers of UIPickerViews how can I optimize this?

我想澄清一下应用程序非常轻巧以及来自Core Data的获取对象只有4,有4 UIPickerView s。

I want to clarify that the app is very light and the fetched objects from Core Data are only 4, with 4 UIPickerViews.

推荐答案

似乎UIPickerViews和UIDatePickers从故事板(可能是xib,但我还没试过)加载速度非常慢。在iPad Air上,它需要大约3秒钟来加载一个静态UITableViewController,其中包含4个UIPickerViews和8个UIDatePickers,位于隐藏单元格中。 (对于在最新和最好的硬件上运行的本机UI,3秒是永恒的!)

It seems that UIPickerViews and UIDatePickers load very slowly from storyboards (and possibly xib's, but I haven't tried). On an iPad Air it's taking around 3 seconds to load a static UITableViewController that contains 4 UIPickerViews and 8 UIDatePickers in "hidden" cells. (3 seconds is an eternity for a native UI running on the latest and greatest hardware!)

我找到的解决方法是在隐藏行之前以编程方式创建UIPickerViews和UIDatePickers透露。我所做的是在Interface Builder中创建空单元格,将这些单元格链接到IBOutlet属性,然后使用以下方法创建DatePickers和Picker视图:

The workaround I found is to create the UIPickerViews and UIDatePickers programmatically before the hidden row is revealed. What I did was create empty cells in Interface Builder, link those cells to IBOutlet properties, and then create the DatePickers and Picker views with these methods:

- (UIDatePicker*)datePickerForCell:(UITableViewCell*)cell {
    UIDatePicker * datePicker = [[UIDatePicker alloc] initWithFrame:cell.bounds];
    [datePicker setDatePickerMode:UIDatePickerModeDateAndTime];
    [datePicker addTarget:self action:@selector(pickerDateChanged:) forControlEvents:UIControlEventValueChanged];
    datePicker.hidden = YES;
    [cell addSubview:datePicker];

    return datePicker;
}

- (UIPickerView*)pickerViewForCell:(UITableViewCell*)cell {
    UIPickerView * picker = [[UIPickerView alloc] initWithFrame:cell.bounds];
    [picker setDelegate:self];
    [picker setDataSource:self];
    picker.hidden = YES;
    [cell addSubview:picker];
    return picker;
}

这将UITableViewController的加载时间减少到十分之几秒它似乎不会影响显示隐藏的tableview的动画。

This reduced the load time for the UITableViewController to a few tenths of a second and it doesn't seem to affect the animation of showing a hidden tableview.

注意:我确实尝试在viewDidAppear:方法中创建拾取器,但它仍然似乎推迟了用户界面。

这篇关于iOS 7使用UIPickerView缓慢打开UITableViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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