2016-03-19 6 views
3

私は、ストーリーボードにWKInterfaceTableCellから別のWKInterfaceController(「DetailInterfaceController」と呼ばれる)のプッシュセグを作成しました。didSelectRowAtIndexがWKInterfaceTableのために呼び出されていません

行をタップすると、didSelectRowAtIndexが呼び出されていません。

誰かが私が間違っている場所を知っていますか、どのように文字列を渡すことができますか?

文が

@IBOutlet var table: WKInterfaceTable! 
var objectsArray = ["1","2","3"] 
var object: String! 

override func table(table: WKInterfaceTable, didSelectRowAtIndex rowIndex: Int) { 
    self.object = self.objectsArray[rowIndex] 

    print(" object title: \(self.object)") 
} 


override func contextForSegueWithIdentifier(segueIdentifier: String) -> AnyObject? { 
    // You may want to set the context's identifier in Interface Builder and check it here to make sure you're returning data at the proper times 

    // Return data to be accessed in ResultsController 
    return self.object 
} 

DetailsInterfaceController

と呼ばれていません

didSelectRowAtIndexPathprint TableInterfaceControllerラベルが設定されていない

@IBOutlet var label: WKInterfaceLabel! 

override func awakeWithContext(context: AnyObject?) { 
    super.awakeWithContext(context) 

    // Make sure data was passed properly and update the label accordingly 
    if let val: String = context as? String { 
     self.label.setText(val) 
    } else { 
     self.label.setText("") 
    } 
    // Configure interface objects here. 
} 

答えて

5

は、なぜ呼び出されていない:

それはあなたがストーリーボードセグエを使用するのでtable:didSelectRowAtIndex:が呼び出されないようにするために、通常です。 WKInterfaceControllerドキュメントから:あなたのストーリーボードファイル内のテーブルにアクションメソッドを接続

場合は、WatchKitは、このメソッドを呼び出すことはありません。

どのように選択された行のデータを渡すために

:あなたが選択した行のコンテキストを返すためにcontextForSegueWithIdentifier:inTable:rowIndex:を使用する必要があります

override func contextForSegueWithIdentifier(segueIdentifier: String, inTable table: WKInterfaceTable, rowIndex: Int) -> AnyObject? { 
    if segueIdentifier == "someSegueIdentifier" { 
     return objectsArray[rowIndex] 
    } 
    return nil 
} 
関連する問題