To Create a SplitViewController in swift follow the steps:-
1- Create a new Project.
2- Add a splitViewController.
3- Create a cocoaTouch Class inherits from UIViewController named as DetailViewController
4- Create another CoCoatouchClass that inherits from UITableViewController names as SideTableViewController
5- Configure the SideTableViewController as
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }
    
   override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let mycell = tableView.dequeueReusableCellWithIdentifier("myCell", forIndexPath: indexPath)
    
        mycell.textLabel?.text = "my cell number is \(indexPath.row)"
        
        return mycell
        
    }
    
   override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10;
        
    }
    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        self.performSegueWithIdentifier("ShowDetail", sender: nil)      
    }
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        
        if (segue.identifier == "ShowDetail") {
            
            let detail = segue.destinationViewController as! DetailViewController
            
            if let path = tableView.indexPathForSelectedRow {
            
                detail.stringFromTable = "Hello you selected the value\(path.row + 1)"
            }  
        }  
}
6- Add a label on DetailViewController and create iboutlet for that label and also create a variable named var stringFromTable = String?()
7- in DetailViewController set the text as  myTextLabel?.text = stringFromTable
8- Create a segue from SideTableViewController (Show Detail Type) and named it is ShowDetail
 
 
                       
                    
0 Comment(s)