Sì, è possibile farlo in swift.Just caricare il tableViewController
come usual.You solo chiamare
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);
La funzione selectRowAtIndexPath
non si innescherà metodi delegato come didSelectRowAtIndexPath:
in modo da avere per attivare manualmente questo metodo delegato
self.tableView(self.tableView, didSelectRowAtIndexPath: rowToSelect); //Manually trigger the row to select
o se si sta spingendo ViewControllers
con seg ue si deve innescare performSegueWithIdentifier
self.performSegueWithIdentifier("yourSegueIdentifier", sender: self);
Ora si può spingere viewController in didSelectRowAtIndexpath
.Per selezionare la prima riga nella prima sezione o eseguire whaterver che hai scritto in didSelectRowAtIndexpath:
di tableView
Per quanto riguarda il tuo caso basta premere il viewController
su Seleziona in corrispondenza dell'indice 0a con 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
}
mostrerà il controller della vista spinto e se non si vuole ani controller di visualizzazione accoppiamento passare semplicemente il metodo NO
a pushViewController
.
Premendo Back
tasto si nuovo al vostro viewController
Nel tuo caso basta scrivere questo nella vostra 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)
}
Nel mio viewDidAppear: '........se firstStart { firstStart = false lasciare rowToSelect: NSIndexPath = NSIndexPath (forRow: 0, inSection: 0) self.tableView.selectRowAtIndexPath (rowToSelect, animato: vero, scrollPosition: UITableViewScrollPosition.None) self.tableView (self.tableView , didSelectRowAtIndexPath: rowToSelect) } 'mia ** ** didSelectRowAtIndexPath:' esclusione func tableView (tableView: UITableView !, didDeselectRowAtIndexPath indexPath: NSIndexPath) { self.performSegueWithIdentifier ("showForecastSelectedCity", mittente: auto) } ' –
errore : '[_TtC12WeatherTest229FavWeatherTableViewController tableView: didSelectRowAtIndexPath:]: selettore non riconosciuto inviato all'istanza 0x7f7fea81d880 *** Terminazione dell'app a causa dell'eccezione non rilevata 'NSI nvalidArgumentException ', motivo:' - [_ TtC12WeatherTest229FavWeatherTableViewController tableView: didSelectRowAtIndexPath:]: selettore non riconosciuto inviato Cosa c'è di sbagliato? –
Poiché non si sta implementando 'didSelectRowAtIndexPath', non è necessario chiamare' self.tableView (self.tableView, didSelectRowAtIndexPath: rowToSelect) '. – codester