Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Chung Teng Chiang
Chung Teng Chiang
4,401 Points

Why it's error...

import UIKit

class ResturantTableViewController: UITableViewController {

var restaurantNames = ["Cafe Deadend", "Homei", "Teakha", "Cafe Loisl", "Petite Oyster", "For Kee Restaurant", "Po's Atelier", "Bourke Street Bakery", "Haigh's Chocolate", "Palomino Espresso", "Upstate", "Traif", "Graham Avenue Meats And Deli", "Waffle & Wolf", "Five Leaves", "Cafe Lore", "Confessional", "Barrafina", "Donostia", "Royal Oak",]
var resturantImages = ["cafedeadend.jpg", "homei.jpg", "teakha.jpg", "cafeloisl.jpg", "petiteoyster.jpg", "forkeerestaurant.jpg", "posatelier.jpg", "bourkestreetbakery.jpg", "haighschocolate.jpg", "palominoespresso.jpg", "upstate.jpg", "traif.jpg", "grahamavenuemeats.jpg", "wafflewolf.jpg", "fiveleaves.jpg", "cafelore.jpg", "cofessional.jpg", "barrafina.jpg", "donostai.jpg", "royaloak.jpg", "thaicafe.jpg"]
var restaurantLocations = ["Hong Kong", "Hong Kong", "Hong Kong", "Hong Kong", "Hong Kong", "Hong Kong", "Hong Kong", "Sydney", "Sydney","Sydney", "New York", "New York", "New York", "New York", "New York", "New York", "New York", "London", "London", "London", "London",]
var restaurantTypes = ["Coffee & Tea Shop", "Cafe", "Tea House", "Austrian /Causual Drink", "French", "Bakery", "Chocolate", "Cafe", "American /Seafood", "American", "American", "Breakfast & Brunch", "Coffee & Tea", "Coffee & Tea", "Latin American", "Spanish", "Spanish", "Spanish", "British", "Thai"]

var restaurantIsVisited = [Bool](count: 21, repeatedValue: false)

override func viewDidLoad() {
    super.viewDidLoad()

    // 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 {
            return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
           return restaurantNames.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath IndexPath:NSIndexPath) -> UITableViewCell {

  let cellIdentifer = "Cell"
  let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifer, forIndexPath: IndexPath) as! RestaurantTableViewCell

    cell.nameLabel.text = restaurantNames[IndexPath.row]
    cell.thumbnailImageView.image = UIImage(named: resturantImages[IndexPath.row])
    cell.typeLabel.text = restaurantTypes[IndexPath.row]
    cell.loactionLabel.text = restaurantLocations[IndexPath.row]
    cell.thumbnailImageView.layer.cornerRadius = 30.0
    cell .thumbnailImageView.clipsToBounds = true
    return cell

} override func tableView(tabelView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { let optionMenu = UIAlertController(title: nil, message: "What do you want to do?", preferredStyle: .ActionSheet)

    let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
    optionMenu.addAction(cancelAction)

    let callActionHandler = { (action:UIAlertAction!) -> Void in
        let alertMessage = UIAlertController(title: "Service Unavailable", message: "Sorry, the call feature is not available yet. Please try later", preferredStyle: .Alert)
        alertMessage.addAction((UIAlertAction(title: "OK", style: .Default, handler: nil)))
        self.presentViewController(optionMenu, animated: true, completion: nil)

} let callAction = UIAlertAction(title: "Call " + "123-000-(indexPath.row)", style: UIAlertActionStyle.Default, handler: callActionHandler) optionMenu.addAction(callAction)

    let isVisitedAction = UIAlertAction(title: "I've been here", style: .Default, handler: {
    (action:UIAlertAction!) -> Void in

        let cell = tableView.cellForRowAtIndexPath(indexPath)
        cell?.accessoryType = .Checkmark
        self.restaurantIsVisited[indexPath.row] = true
    })

    optionMenu.addAction(isVisitedAction)

    self.presentViewController(optionMenu, animated: true, completion: nil)

    tableView.deselectRowAtIndexPath(indexPath, animated: false)

}

}

1 Answer

Oleksii Gamalii
Oleksii Gamalii
7,157 Points

Can you tell what is the error you get?