问题
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.
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.
-
Can some UIPickerView
s make the transition so slow and pretty ugly?
In which mode should I use Instruments to understand which is the slowly-guilty?
More important: if the slowness is derived from the numbers of UIPickerView
s how can I optimize this?
I want to clarify that the app is very light and the fetched objects from Core Data are only 4, with 4 UIPickerView
s.
回答1:
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!)
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;
}
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.
Note: I did try creating the pickers in the viewDidAppear: method, but it still seemed to delay the UI.
来源:https://stackoverflow.com/questions/19239003/ios-7-slow-to-open-uitableviewcontroller-with-uipickerview