Can UIImagePickerController be used directly on story board?
I have an impression that ViewController usage are similar: on story board, we drag an UIViewController onto scene, then change its class type, e.g. to UIImagePickerController. (I want to make a dedicated scene for picking images)
But later I find that UIImagePickerController
won't work if I directly subclass:
class TestUIImagePickerController: UIImagePickerController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
self.sourceType = .photoLibrary
self.delegate = self
// self.present(self, animated: true) // either comment it out or not, both way won't work.
}
But it works only if I put an UIViewController
on storyboard, then construct an UIImagePickerController
programmatically:
class SecondTestUIImagePickerController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let picker = UIImagePickerController()
picker.sourceType = .photoLibrary
picker.delegate = self
self.present(picker, animated: true)
}
May I know whether I missed anything in the first usage example? And is it a must to create UIImagePickerController
programmatically then present it via an agent view controller (UIVIewController)?
ios swift uiimagepickercontroller
add a comment |
I have an impression that ViewController usage are similar: on story board, we drag an UIViewController onto scene, then change its class type, e.g. to UIImagePickerController. (I want to make a dedicated scene for picking images)
But later I find that UIImagePickerController
won't work if I directly subclass:
class TestUIImagePickerController: UIImagePickerController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
self.sourceType = .photoLibrary
self.delegate = self
// self.present(self, animated: true) // either comment it out or not, both way won't work.
}
But it works only if I put an UIViewController
on storyboard, then construct an UIImagePickerController
programmatically:
class SecondTestUIImagePickerController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let picker = UIImagePickerController()
picker.sourceType = .photoLibrary
picker.delegate = self
self.present(picker, animated: true)
}
May I know whether I missed anything in the first usage example? And is it a must to create UIImagePickerController
programmatically then present it via an agent view controller (UIVIewController)?
ios swift uiimagepickercontroller
add a comment |
I have an impression that ViewController usage are similar: on story board, we drag an UIViewController onto scene, then change its class type, e.g. to UIImagePickerController. (I want to make a dedicated scene for picking images)
But later I find that UIImagePickerController
won't work if I directly subclass:
class TestUIImagePickerController: UIImagePickerController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
self.sourceType = .photoLibrary
self.delegate = self
// self.present(self, animated: true) // either comment it out or not, both way won't work.
}
But it works only if I put an UIViewController
on storyboard, then construct an UIImagePickerController
programmatically:
class SecondTestUIImagePickerController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let picker = UIImagePickerController()
picker.sourceType = .photoLibrary
picker.delegate = self
self.present(picker, animated: true)
}
May I know whether I missed anything in the first usage example? And is it a must to create UIImagePickerController
programmatically then present it via an agent view controller (UIVIewController)?
ios swift uiimagepickercontroller
I have an impression that ViewController usage are similar: on story board, we drag an UIViewController onto scene, then change its class type, e.g. to UIImagePickerController. (I want to make a dedicated scene for picking images)
But later I find that UIImagePickerController
won't work if I directly subclass:
class TestUIImagePickerController: UIImagePickerController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
self.sourceType = .photoLibrary
self.delegate = self
// self.present(self, animated: true) // either comment it out or not, both way won't work.
}
But it works only if I put an UIViewController
on storyboard, then construct an UIImagePickerController
programmatically:
class SecondTestUIImagePickerController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let picker = UIImagePickerController()
picker.sourceType = .photoLibrary
picker.delegate = self
self.present(picker, animated: true)
}
May I know whether I missed anything in the first usage example? And is it a must to create UIImagePickerController
programmatically then present it via an agent view controller (UIVIewController)?
ios swift uiimagepickercontroller
ios swift uiimagepickercontroller
edited Jan 2 at 2:19


rmaddy
245k27324388
245k27324388
asked Jan 2 at 2:16
modellermodeller
1,85211227
1,85211227
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
self.present(self, animated: true)
you can not self
present self
, use another ViewController
to present UIImagePickerController
UIImagePickerController
can be used on Story board, in your code, for example
class SecondTestUIImagePickerController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let sb = UIStoryboard(name: "ImagePickerStoryboard", bundle: nil)
let picker = sb.instantiateViewControllerWithIdentifier("ImagePicker") as! TestUIImagePickerController
self.present(picker, animated: true)
}
keep in mind that UIImagePickerController
is subclass of UINavigationController
So, not all ViewControllers are equal (in terms of usage): i.e. UIViewController can be used directly by placement on Story board, but some view controller, e.g. UIImagePickerController, MUST use a proxy viewcontroller to present it. Am I right?
– modeller
Jan 2 at 2:34
update my answer, initTestUIImagePickerController
(subclass of UIImagePickerController) from storyboard
– Ethan
Jan 2 at 2:53
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54000500%2fcan-uiimagepickercontroller-be-used-directly-on-story-board%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
self.present(self, animated: true)
you can not self
present self
, use another ViewController
to present UIImagePickerController
UIImagePickerController
can be used on Story board, in your code, for example
class SecondTestUIImagePickerController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let sb = UIStoryboard(name: "ImagePickerStoryboard", bundle: nil)
let picker = sb.instantiateViewControllerWithIdentifier("ImagePicker") as! TestUIImagePickerController
self.present(picker, animated: true)
}
keep in mind that UIImagePickerController
is subclass of UINavigationController
So, not all ViewControllers are equal (in terms of usage): i.e. UIViewController can be used directly by placement on Story board, but some view controller, e.g. UIImagePickerController, MUST use a proxy viewcontroller to present it. Am I right?
– modeller
Jan 2 at 2:34
update my answer, initTestUIImagePickerController
(subclass of UIImagePickerController) from storyboard
– Ethan
Jan 2 at 2:53
add a comment |
self.present(self, animated: true)
you can not self
present self
, use another ViewController
to present UIImagePickerController
UIImagePickerController
can be used on Story board, in your code, for example
class SecondTestUIImagePickerController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let sb = UIStoryboard(name: "ImagePickerStoryboard", bundle: nil)
let picker = sb.instantiateViewControllerWithIdentifier("ImagePicker") as! TestUIImagePickerController
self.present(picker, animated: true)
}
keep in mind that UIImagePickerController
is subclass of UINavigationController
So, not all ViewControllers are equal (in terms of usage): i.e. UIViewController can be used directly by placement on Story board, but some view controller, e.g. UIImagePickerController, MUST use a proxy viewcontroller to present it. Am I right?
– modeller
Jan 2 at 2:34
update my answer, initTestUIImagePickerController
(subclass of UIImagePickerController) from storyboard
– Ethan
Jan 2 at 2:53
add a comment |
self.present(self, animated: true)
you can not self
present self
, use another ViewController
to present UIImagePickerController
UIImagePickerController
can be used on Story board, in your code, for example
class SecondTestUIImagePickerController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let sb = UIStoryboard(name: "ImagePickerStoryboard", bundle: nil)
let picker = sb.instantiateViewControllerWithIdentifier("ImagePicker") as! TestUIImagePickerController
self.present(picker, animated: true)
}
keep in mind that UIImagePickerController
is subclass of UINavigationController
self.present(self, animated: true)
you can not self
present self
, use another ViewController
to present UIImagePickerController
UIImagePickerController
can be used on Story board, in your code, for example
class SecondTestUIImagePickerController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let sb = UIStoryboard(name: "ImagePickerStoryboard", bundle: nil)
let picker = sb.instantiateViewControllerWithIdentifier("ImagePicker") as! TestUIImagePickerController
self.present(picker, animated: true)
}
keep in mind that UIImagePickerController
is subclass of UINavigationController
edited Jan 2 at 2:50
answered Jan 2 at 2:24
EthanEthan
353310
353310
So, not all ViewControllers are equal (in terms of usage): i.e. UIViewController can be used directly by placement on Story board, but some view controller, e.g. UIImagePickerController, MUST use a proxy viewcontroller to present it. Am I right?
– modeller
Jan 2 at 2:34
update my answer, initTestUIImagePickerController
(subclass of UIImagePickerController) from storyboard
– Ethan
Jan 2 at 2:53
add a comment |
So, not all ViewControllers are equal (in terms of usage): i.e. UIViewController can be used directly by placement on Story board, but some view controller, e.g. UIImagePickerController, MUST use a proxy viewcontroller to present it. Am I right?
– modeller
Jan 2 at 2:34
update my answer, initTestUIImagePickerController
(subclass of UIImagePickerController) from storyboard
– Ethan
Jan 2 at 2:53
So, not all ViewControllers are equal (in terms of usage): i.e. UIViewController can be used directly by placement on Story board, but some view controller, e.g. UIImagePickerController, MUST use a proxy viewcontroller to present it. Am I right?
– modeller
Jan 2 at 2:34
So, not all ViewControllers are equal (in terms of usage): i.e. UIViewController can be used directly by placement on Story board, but some view controller, e.g. UIImagePickerController, MUST use a proxy viewcontroller to present it. Am I right?
– modeller
Jan 2 at 2:34
update my answer, init
TestUIImagePickerController
(subclass of UIImagePickerController) from storyboard– Ethan
Jan 2 at 2:53
update my answer, init
TestUIImagePickerController
(subclass of UIImagePickerController) from storyboard– Ethan
Jan 2 at 2:53
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54000500%2fcan-uiimagepickercontroller-be-used-directly-on-story-board%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown