swift - prepareForSeague error when running -
i'm creating application allows user click item in uitableview goes new screen information on clicked. i'm receiving 1 error when attempting run.
import uikit class cartableviewcontroller: uitableviewcontroller { var cars = [cars]() override func viewdidload() { super.viewdidload() var newcar = cars(name: "audi", image: "iphone6", details: "iphone 6, apple, 2015") cars.append(newcar) newcar = cars(name: "bmw", image: "iphone6plus", details: "iphone 6 plus, apple, 2015") cars.append(newcar) newcar = cars(name: "bugatti", image: "iphone6plus", details: "iphone 6 plus, apple, 2015") cars.append(newcar) newcar = cars(name: "mercedes", image: "iphone6plus", details: "iphone 6 plus, apple, 2015") cars.append(newcar) newcar = cars(name: "lamboghini", image: "iphone6plus", details: "iphone 6 plus, apple, 2015") cars.append(newcar) newcar = cars(name: "ferrari", image: "iphone6plus", details: "iphone 6 plus, apple, 2015") cars.append(newcar) newcar = cars(name: "bmw", image: "iphone6plus", details: "iphone 6 plus, apple, 2015") cars.append(newcar) // uncomment following line preserve selection between presentations // self.clearsselectiononviewwillappear = false // uncomment following line display edit button in navigation bar view controller. // self.navigationitem.rightbarbuttonitem = self.editbuttonitem() } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } // mark: - table view data source override func numberofsectionsintableview(tableview: uitableview) -> int { // #warning potentially incomplete method implementation. // return number of sections. return 1 } override func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int { // #warning incomplete method implementation. // return number of rows in section. return cars.count } override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { let cell = tableview.dequeuereusablecellwithidentifier("carcell", forindexpath: indexpath) as! uitableviewcell // configure cell... var currentcars = cars[indexpath.row] cell.textlabel?.text = currentcars.carname return cell } /* // override support conditional editing of table view. override func tableview(tableview: uitableview, caneditrowatindexpath indexpath: nsindexpath) -> bool { // return no if not want specified item editable. return true } */ /* // override support editing table view. override func tableview(tableview: uitableview, commiteditingstyle editingstyle: uitableviewcelleditingstyle, forrowatindexpath indexpath: nsindexpath) { if editingstyle == .delete { // delete row data source tableview.deleterowsatindexpaths([indexpath], withrowanimation: .fade) } else if editingstyle == .insert { // create new instance of appropriate class, insert array, , add new row table view } } */ /* // override support rearranging table view. override func tableview(tableview: uitableview, moverowatindexpath fromindexpath: nsindexpath, toindexpath: nsindexpath) { } */ /* // override support conditional rearranging of table view. override func tableview(tableview: uitableview, canmoverowatindexpath indexpath: nsindexpath) -> bool { // return no if not want item re-orderable. return true } */ // mark: - navigation // in storyboard-based application, want little preparation before navigation override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) { var nextscene = segue.destinationviewcontroller as! displayviewcontroller if let indexpath = self.tableview.indexpathforselectedrow() { let selectedcar = cars [indexpath.row] nextscene.selectedcar = selectedcar } } i receive error @ bottom line stating expected declaration. i've attempted many ways fix can't figure out.
how try way-
rather going hassle attach segue , all, can use delegate method, didselectrowatindexpath
func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath){ var nextscene = displayviewcontroller() let selectedcar = cars [indexpath.row] nextscene.selectedcar = selectedcar //then push view controller on top of current view controller self.navigationcontroller.pushviewcontroller(nextscene, animated: true) } off course, need conform uitableviewdelegate.
Comments
Post a Comment