I've created custom tableView Controller, inside the cell i've placed a button to open the device photo library. My problem, i cant able to open imagePickerController from CustomCell.m, its shows below error.
Please give some idea to fix my issue.
I've created custom tableView Controller, inside the cell i've placed a button to open the device photo library. My problem, i cant able to open imagePickerController from CustomCell.m, its shows below error.
Please give some idea to fix my issue.
The answers proposing a delegate or instance variable are correct, but, however, in most cases it is not important to use a special view controller to present the new controller. In these cases the following solution is much simpler: Just use the applications root view controller:
Make IBOutlet of your button
Then in
cellForRowAtIndexPath
give target to the buttonOne other way to do this is pass reference of the controller of the CustomCell to the CustomCell and use that to present the new controller.
Swift:
CustomCell.swift
:ViewController.swift
:You need a
UIViewController
to present from. There are a few things you can do here. One would be to create a custom delegate protocol with achangePicturePressed
callback method. Then you can assign the containing view controller as that delegate and perform the presentation in the delegate method.The other thing you can do is pass the
UIViewController
into your cell during initialization and set it as a weak property. Then you can perform the presentation directly from inside the cell using that property.You need viewcontroller for presenting the view. You cannot present viewcontroller on tableviewcells.
presentViewController:
message is there for Viewcontroller. Do delegate the control from Cell to viewController and use the same line would solve your problem. UITableViewCell does not responds topresentViewController:
message.