iPhone dev noob question: Invoking action explicitly on application launch
I just started getting into iPhone development. I have been mish-mashing tutorials and material from books in order to get my bearings straight. I come from a PHP and Java background... Objective-C is a bit quirky.开发者_高级运维 But, I learn best by getting my feet wet.
Basically, I have these actions. getPhoto is bound to a couple of UIBarButtonItems in my view.
-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIBarButtonItem *) sender == choosePhoto) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
theimageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}
My goal is to invoke the same action once the application launches, automatically opening the Camera. How would I go about this?
EDIT:
As per this SO question you should actually place it in viewWillAppear
or viewDidAppear
Add a similar method to the ApplicationDidFinishLaunching
method in the app delegate.
Might be better to place the call in the ViewDidLoad
of your root view controller
精彩评论