2016-04-02 21 views
1

私はSwiftを初めて使用しています。 「itemNameに型のListItem上で使用することはできませんインスタンスメンバー」:私は私のTableViewControllerでこのクラスを参照するとき、私は次のエラーを取得する迅速Swiftでクラスを呼び出すとエラーが発生する

class ListItem: NSObject { 
let itemName: String 
var completed: Bool 

init(itemName: String, completed: Bool = false) 
{ 
self.itemName = itemName 
self.completed = completed 
} 
} 

に単純なクラスを持っています。

My TableViewControllerコード(cellForRowAtIndexPathメソッド)を以下に示します。

let tempCell = tableView.dequeueReusableCellWithIdentifier("triggerCell")! as UITableViewCell 
    let listItem = listItems[indexPath.row] 

    // Downcast from UILabel? to UILabel 
    let cell = tempCell.textLabel as UILabel! 


    cell.text = ListItem.itemName 

    if (ListItem.completed) 
    { 
     tempCell.accessoryType = UITableViewCellAccessoryType.Checkmark; 
    } 
    else 
    { 
     tempCell.accessoryType = UITableViewCellAccessoryType.None; 
    } 

    return tempCell 
} 

おそらく基本的なエラーですが、どこが間違っているのかわかりません。

答えて

1

インスタンスの代わりにクラスを呼び出しています。これを試してください:

cell.text = listItem.itemName 

if (listItem.completed) 
etc... 

EDIT:listItemsの作成を更新しています。

let listItems = [ListItem("Viruses"), ListItem("Changes in weather"), etc...] 
+0

おかげで - 私はそれをしようとしたが、「『文字列』はメンバーがないタイプの値 『itemNameに』」のエラーが表示されます – stiva

+0

のlistItems配列の型は何ですか? [文字列]または[ListItem]? – Mark

+0

文字列 let listItems = [ウイルス、天気の変化、ハウスダストのダニ、動物のふらつき、食べ物、運動、怒りと感情、煙とたばこと火災"] – stiva

関連する問題