我一直在努力过去一段时间,应该很容易,但我似乎无法开始工作。我在WatchKit界面上绑定了一个现有iPhone应用程序,该应用程序在Objective-C开发的App Store中销售。我只是想在将对象传递给下一个WKInterfaceController
时,我滑动以继续播放它。在基于页面的WatchKit应用程序中的WKInterfaceControllers之间传递对象
鉴于WatchKit没有prepareForSegue,并且基于页面的关系分段没有可以使用contextForSegueWithIdentifier
的标识符(我可以告诉),我该如何去传递一个对象?
我曾尝试:
_names = [[NSArray alloc]initWithObjects:@"RootInterfaceController",@"StatusInterfaceController",nil];
NSString *[email protected]"TEST";
_contextObject=[[NSArray alloc]initWithObjects:passedBAL, nil];
if (firstLoad) {
[WKInterfaceController reloadRootControllersWithNames:_names
contexts:_contextObject];
firstLoad=NO;
在-(void)willActivate
,在那里我已经在-(void)awakeWithContext:(id)context
设定的数值作为_passedBal
财产和BOOL避免无限递归这种方法似乎产生了(很缺憾修复在我看来),但是当我到达下一个WKInterfaceController
时,价值总是零。当我在StatusInterfaceController
的变量上设置断点和鼠标时,它似乎设置了该值,但是随着程序继续执行,它立即删除,但不响应我在代码中写入的任何内容。
任何帮助将不胜感激,因为我一直在这一个拉我的头发,正如我所说,它应该死了简单。
编辑:
_passedBAL
是一个简单的NSString财产,但我已经在上面的改变它只是一个直线上升的NSString把数组中为清楚起见,并加入我的StatusInterfaceController
代码。感谢提前:)
在我StatusInterfaceController.h,我有以下几点:
#import <WatchKit/WatchKit.h>
#import <Foundation/Foundation.h>
#import "InterfaceController.h"
@interface StatusInterfaceController : WKInterfaceController
@property (strong, nonatomic) NSString *passedBAL;
@end
虽然我StatusInterfaceController.m我:
#import "StatusInterfaceController.h"
@interface StatusInterfaceController()
@end
@implementation StatusInterfaceController
- (void)awakeWithContext:context {
[super awakeWithContext:context];
_passedBAL=[context objectAtIndex:0];
NSLog(@"Passed BAL is equal to %@",_passedBAL);
// Configure interface objects here.
}
谢谢,但从我所知道的,你不能设置关系Segue(基于页面的导航)的标识符。当您突出显示时,属性菜单下没有可用的选项。在你的第二个解决方案中,我需要创建一个按钮来继续,当我只想要通过滑动传递的信息(显然,它也不能作为接口对象添加到WatchKit中)。任何想法,我会如何做到这一点? –
对不起,您不明白您正在谈论基于页面的导航(请在您的问题中明确说明以缩小将来的答案)。据我所知,最好的方法是用不同的上下文重新加载你的视图控制器,看起来你已经在做这件事了。 –
感谢蒂亚戈,也许我的代码是在接收端扭曲...那么在我接收WKViewController,我有 - (void)awakeWithContext:context {superwakeWithContext:context]; _passedBAL = [context objectAtIndex:0]; (@“通过的BAL等于%@”,_ passedBAL);如果我有一个属性设置,并且我将这个值传递给一个NSArray,我选择了第一个对象。那是不正确的? –