prepareForSegue equivalent in WatchKit

风流意气都作罢 提交于 2019-12-01 03:08:45

You can do this in two ways:

In your storyboard you set an identifier in your segue:

and then you can use contextForSegueWithIdentifier:

- (id)contextForSegueWithIdentifier:(NSString *)segueIdentifier {
     if ([segueIdentifier isEqualToString:@"yourIdentifier"]) {
        return aDictionaryWithYourInformation;
     }
}

Or you can pass information with a context via code, with:

[self pushControllerWithName:@"YourViewController"
                     context:aDictionary];

This context is a dictionary and you have access to this dictionary in the - (void)awakeWithContext:(id)context

For segue navigation in Watchkit there are two methods in WKInterfaceController:

override func contextForSegueWithIdentifier(segueIdentifier: String) -> AnyObject? {
        return //your object
    }

and for tables

override func contextsForSegueWithIdentifier(segueIdentifier: String, inTable table: WKInterfaceTable, rowIndex: Int) -> [AnyObject]? {
      return  //your object
    }

you can get the object you are passing in func awakeWithContext(context: AnyObject?) of the interface controller you are pushing

VladZ

In WatchKit, you can use this for calling WKInterfaceController:

[self pushControllerWithName:@"YourControlName"
          context:[self contextForSegueWithIdentifier:@"YourControlName"]];

For tables it's the following:

override func contextForSegue(withIdentifier segueIdentifier: String, in table: WKInterfaceTable, rowIndex: Int) -> Any? {
     return  //your object
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!