2016-09-05 3 views
-1

私はスウィフトに新たなんだとIOSのプログラミングを勉強するには、次のAppcodaの本を持っていない、ここに私のコードは次のとおりです。 -In restaurantDetailViewControllerクラス:型「ブール値は」は添字メンバー

class RestaurantDetailViewController: UIViewController,UITableViewDataSource,UITableViewDelegate { 
@IBOutlet var restaurantImageView:UIImageView! 
@IBOutlet var restaurantNameLabel:UILabel! 
@IBOutlet var restaurantTypeLabel:UILabel! 
@IBOutlet var restaurantLocationLabel:UILabel! 

var restaurantImage = "" 
var restaurantName = "" 
var restaurantType = "" 
var restaurantLocation = "" 
var isVisited:Bool? 

func tableView(tableView:UITableView,numberOfRowsInSection section:Int)->Int{ 
    return 4 
} 
func tableView(tableView:UITableView,cellForRowAtIndexPath indexPath:NSIndexPath) -> UITableViewCell{ 
    let cellIndentifier = "Cell" 
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as!RestaurantDetailViewCell 
    switch indexPath.row{ 
    case 0: 
     cell.filedLabel.text = "Name" 
     cell.valueLabel.text = restaurantName 
    case 1: 
     cell.filedLabel.text = "Type" 
     cell.valueLabel.text = restaurantType 
    case 2: 
     cell.filedLabel.text = "Location" 
     cell.valueLabel.text = restaurantLocation 
    case 3: 
     cell.filedLabel.text = "Been here?" 
     cell.valueLabel.text = isVisited[indexPath.row] ? "Yes, I have been here" : "No"//I got the error right here 

    default: 
     cell.filedLabel = nil 
     cell.valueLabel = nil 

    } 
    return cell 
} 
override func viewDidLoad() { 
    super.viewDidLoad() 

    // Do any additional setup after loading the view. 
    restaurantImageView.image = UIImage(named: restaurantImage) 
    //restaurantNameLabel.text = restaurantName 
    //restaurantTypeLabel.text = restaurantType 
    //restaurantLocationLabel.text = restaurantLocation 
} 

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


/* 
// 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?) { 
    // Get the new view controller using segue.destinationViewController. 
    // Pass the selected object to the new view controller. 
} 
*/ 

}

私は私の問題について多くのトピックを検索したが、私は手がかりを得ていない、あなたが私を助けることができれば非常に感謝します。これは、私は私の質問に私のトピックを間違っている場合、私はあなたが私を優しく思い出させることができることを願って質問をする方法をstackoverflowに私の質問を投稿する初めてです。 ありがとうございました。

+0

ジャスト削除 '[indexPath.row]' - > 'isVisited? "はい、私はここにいました": "いいえ"。 – vadian

+0

私はあなたに真剣に何かを考えます_model_、一見、あなたはちょうど_model_を持っていないので。 – holex

+1

PS:オプションとして 'isVisited'を宣言することは無意味です。 「はい」または「いいえ」として他に何かありますか? – vadian

答えて

0

iSVisited はオプションのブール

var isVisited:Bool? 

として宣言されているが、以下のようにあなたのcase3更新: -

cell.valueLabel.text = isVisited ? "Yes, I have been here" : "No" 
+0

私はあなたの指示通りでしたが、私はエラーが発生しました: "オプションの型 '()'をブール値として使うことはできません。代わりに '!= nil'をテストしてください。 どうすればこの問題を解決できますか? –

+0

ああ、私はisVisitedにデフォルト値としてfalseを設定し、アプリケーションが正しく動作することで解決策を見つけました。 –

関連する問題