PresentViewController from custom TableCell in xib
TableViewCell is a view, you can not present
on views instead UIViewController can handle it. You should transfer the control from your cell to your controller that holds tableview and creates custom cell for it.
Try like this:
Custom Cell .h
Class:
@protocol changePictureProtocol <NSObject>
-(void)loadNewScreen:(UIViewController *)controller;
@end
@property (nonatomic, retain) id<changePictureProtocol> delegate;
Then Synthesize it in
.m.
Add this in m
file:
-(IBAction)changePicture:(id)sender
{
// ..... blah blah
[self.delegate loadNewScreen:picker];
}
The viewcontroller that loads this cell:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// create cell here
cell.delegate = self;
}
-(void)loadNewScreen:(UIViewController *)controller;
{
[self presentViewController:controller animated:YES completion:nil];
}
Its a psuedocode to give you an idea.
EDIT:
Swift equivalent:
CustomTableViewCell.swift
code:
protocol ChangePictureProtocol : NSObjectProtocol {
func loadNewScreen(controller: UIViewController) -> Void;
}
class CustomTableViewCell: UITableViewCell {
// Rest of the class stuff
weak var delegate: ChangePictureProtocol?
@IBAction func changePicture(sender: AnyObject)->Void
{
var pickerVC = UIImagePickerController();
if((delegate?.respondsToSelector("loadNewScreen:")) != nil)
{
delegate?.loadNewScreen(pickerVC);
}
}
}
ViewController.swift
code:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
var cell = tableView.dequeueReusableCellWithIdentifier("cellIdentifier") as CustomTableViewCell!
cell.delegate = self;
return cell;
}
func loadNewScreen(controller: UIViewController) {
self.presentViewController(controller, animated: true) { () -> Void in
};
}
Load or Push viewcontroller from tableviewcell class
You have to either pass your navigation controller instance through to the collectionView cell and use it there to push(bad, lazy idea)
OR
Create a protocol delegate to inform your ViewController that your CollectionView selected something and push from the ViewController.
Show ViewController from XIB-file-Button - Swift
You can always instantiate a view controller from your Storyboard and present it on button tapped:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("ViewControllerID") as UIViewController
self.presentViewController(vc, animated: true, completion: nil)
Performing Segue from - TableViewCell.xib to UIView - and - TableView.xib to UIViewController -
Your second approach looks to be right one but of course you are doing something wrong there. You need to drag and drop Segue from Parent ViewController to Detail ViewController and give it a Segue identifier in Storyboard (check attached Image below). IN didSelectRowAtIndexPath you need to do below code:
self.performSegueWithIdentifier("showDetailViewController", sender: nil)
As I can see you already tried that but it looks like you missed some step either setting Segue Identifier or giving wrong identifier in performSegueWithIdentifier method. Also your Parent ViewController should be embedded in UINavigationController in case you are missing that thing :)
Also keep in mind you should perform navigation (here its Segue) from one ViewController to another ViewController at same level not from one View to another ViewController.
Related Topics
Ibeacon Notification When the App Is Not Running
How to Open Mail App from Swift
How to Implement Auto-Complete for Address Using Apple Map Kit
My App Was Just Rejected for Using the Ad Support Framework. Which Library Is Responsible
How to Get the Font Name from an Otf or Ttf File
What Is the Second Parameter of Nslocalizedstring()
How to Access My Viewcontroller from My Appdelegate? iOS
Programmatically Set Image to Uiimageview with Xcode 6.1/Swift
iOS 9 Safari: Changing an Element to Fixed Position While Scrolling Won't Paint Until Scroll Stops
Uibutton Fails to Properly Register Touch in Bottom Region of iPhone Screen
Swift Countelements() Return Incorrect Value When Count Flag Emoji
Presentviewcontroller from Custom Tablecell in Xib
Application Loader Stuck at "Authenticating with the Itunes Store" When Uploading an iOS App
Why Xcode 7 Shows *.Tbd Instead of *.Dylib
Xcode 10 (iOS 12) Does Not Contain Libstdc++6.0.9
Uialertview/Uialertcontroller iOS 7 and iOS 8 Compatibility
Swift - How to Remove a Decimal from a Float If the Decimal Is Equal to 0