2015-05-14 2 views
0

Я создаю приложение, которое позволяет пользователю щелкнуть элемент в UITableView, который затем переходит на новый экран с информацией о том, что они нажали. При попытке запуска я получаю одну ошибку.makeForSeague error при запуске

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 the following line to preserve selection between presentations 
    // self.clearsSelectionOnViewWillAppear = false 

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
    // self.navigationItem.rightBarButtonItem = self.editButtonItem() 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

// MARK: - Table view data source 

override func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
    // #warning Potentially incomplete method implementation. 
    // Return the number of sections. 
    return 1 
} 

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    // #warning Incomplete method implementation. 
    // Return the number of rows in the section. 
    return cars.count 
} 


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCellWithIdentifier("carCell", forIndexPath: indexPath) as! UITableViewCell 

    // Configure the cell... 

     var currentCars = cars[indexPath.row] 
     cell.textLabel?.text = currentCars.carName 

    return cell 
} 


/* 
// Override to support conditional editing of the table view. 
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { 
    // Return NO if you do not want the specified item to be editable. 
    return true 
} 
*/ 

/* 
// Override to support editing the table view. 
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { 
    if editingStyle == .Delete { 
     // Delete the row from the data source 
     tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade) 
    } else if editingStyle == .Insert { 
     // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view 
    }  
} 
*/ 

/* 
// Override to support rearranging the table view. 
override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) { 

} 
*/ 

/* 
// Override to support conditional rearranging of the table view. 
override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool { 
    // Return NO if you do not want the item to be re-orderable. 
    return true 
} 
*/ 


// MARK: - Navigation 

// In a storyboard-based application, you will often want to do a 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 
} 
} 

В нижней строке отображается ожидаемая декларация. Я попытался так много способов исправить это, но я не могу понять это.

+0

Вы выполняете segue в пути didSelectRowAtIndex? Можем ли мы показать больше вашей работы? –

+0

обновил его для вас, помогает ли это? – swiftAssist

+0

Думаю, вам не хватает закрывающей скобки. Можете ли вы быстро проверить? –

ответ

0

Как насчет попробовать это ПУТЬ

Вместо того, чтобы идти к хлопот, чтобы прикрепить SEGUE и все, что вы можете просто использовать метод делегата, didSelectRowAtIndexPath

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){ 
     var nextScene = DisplayViewController() 
     let selectedCar = cars [indexPath.row] 
     nextScene.selectedCar = selectedCar 

     //then push the view controller on top of your current view controller 
     self.navigationController.pushViewController(nextScene, animated: true) 
    } 

Конечно же, вам нужно соответствовать UITableviewDelegate.

Смежные вопросы