我一直在努力過去一段時間,應該很容易,但我似乎無法開始工作。我在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,我選擇了第一個對象。那是不正確的? –