Yes you can do this in swift.Just load your tableViewController
as usual.You just have to call
In Swift
let rowToSelect:NSIndexPath = NSIndexPath(forRow: 0, inSection: 0); //slecting 0th row with 0th section
self.tableView.selectRowAtIndexPath(rowToSelect, animated: true, scrollPosition: UITableViewScrollPosition.None);
The selectRowAtIndexPath
function will not trigger delegate methods like didSelectRowAtIndexPath:
so you have to manually trigger this delegate method
self.tableView(self.tableView, didSelectRowAtIndexPath: rowToSelect); //Manually trigger the row to select
Or If you are pushing ViewControllers
with segue you have to trigger performSegueWithIdentifier
self.performSegueWithIdentifier("yourSegueIdentifier", sender: self);
Now you can push viewController in didSelectRowAtIndexpath
.To select the first row in first section or execute whaterver you have written in didSelectRowAtIndexpath:
of tableView
As For your case just push the viewController
on select at 0th index with didSelectRowAtIndexPath
func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!){
if indexPath.row == 0 {
self.navigationController.pushViewController(yourViewControllerToPush, animated: YES);
}
//handle other index or whatever according to your conditions
}
It will show the view controller pushed and if you do not want to animate view controller just pass NO
to pushViewController
method.
On pressing Back
button you will back to your viewController
In your case just write this in your viewDidAppear
if firstStart {
firstStart = false
let rowToSelect:NSIndexPath = NSIndexPath(forRow: 0, inSection: 0)
self.tableView.selectRowAtIndexPath(rowToSelect, animated: true, scrollPosition:UITableViewScrollPosition.None)
self.performSegueWithIdentifier("showForecastSelectedCity", sender: self)
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…