Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
696 views
in Technique[技术] by (71.8m points)

ios - UIImagePickerController really slow when calling alloc init

I have a view controller that is presented on pressing on one of the tabs in a tabBarController. In this view controller I initialise a UIImagePickerController in the viewDidLoad method:

- (void)viewDidLoad
{
    [super viewDidLoad];

    //Set imagePicker
    //-------------------------//
    _imagePicker = [[UIImagePickerController alloc] init];
    _imagePicker.delegate = self;
    _imagePicker.videoMaximumDuration = 10.0f;
}

The intention is to then display the UIImagePickerController at a later time when a button is pressed. For some reason though when the tab icon is pressed for this view controller, there is a 3-4 second hang while this viewDidLoad method is running. When I comment out the line _imagePicker = [[UIImagePickerController alloc] init] there is no hang time and the view controller loads immediately - as it should.

Does anyone know why allocating and initialising the UIImagePickerController is taking so long? If so, is there a way to speed it up other than running it as a background process? It seems like this is not normal behaviour.

I am using iOS7, and I am not calling viewWillAppear or viewDidAppear.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Turns out this is only a problem when in debug mode (when the iPhone is connected and running through Xcode). Once the same app is running without being connected to Xcode the lag doesn't occur.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...