1
votes

I have a Tabbar controller and in that controller I am showing more then 5 viewcontroller. everything is working as expected.

But now I have a ViewController that has UiTableView, On the cell click I want to open a DetailView Controller.

That DetailViewController will be Having a Title in the Navigation View Controller and the backbutton to go back again to list.

Please help me how to do it using Swift?

4
now I have a ViewController that has UiTableView this one from the tabs ??Sh_Khan
yes. that is from tabAndroid teem

4 Answers

3
votes

The vc you want to show the detailVC from should be embedded inside a navigationController , then use push/pop to manage show/hide

let vc = ///

self.navigationController?.pushViewController(vc, animated: true)

//

self.navigationController?.popViewController(animated: true)
2
votes
import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

@IBAction func moveToNexScreen(_ sender: Any) {
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let nextVc = storyboard.instantiateViewController(withIdentifier: "NextViewController") as! NextViewController
    let navigationVc = UINavigationController(rootViewController: nextVc)
    present(navigationVc, animated: false, completion: nil)
}
}

class NextViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(self.closeBackButtonPressed))        
}

@objc func closeBackButtonPressed(){
    self.dismiss(animated: false, completion: nil)
}
}

Put your detailView inside UINavigationController(rootViewController: detailVc) and then you can present it and to have a back button you can add a barbutton item on the detailsView programatically

0
votes

USE -

#import <DetailViewController.h>

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

    NSIndexPath *indexPath = [_tableView indexPathForCell:sender];

    DetailViewController *details = (DetailViewController *)segue.destinationViewController;

    details.dictionary = _json[indexPath.row]; // to pass data

}

In Storyboard -

Select Cell and drag a segue to Details view controller
0
votes

Maybe this storyboard illustration will help you. It's clean to show the vcs you need. enter image description here