0
看來你可以在android中使用下面的代碼只保留一個活動的一個實例。ios,像android一樣維護單個viewcontroller?
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
如何在ios中實現相同的效果?
看來你可以在android中使用下面的代碼只保留一個活動的一個實例。ios,像android一樣維護單個viewcontroller?
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
如何在ios中實現相同的效果?
有這樣做的沒有標準的方式,但你可以讓你的視圖控制器單是這樣的:
+ (instancetype *)sharedViewController {
static FooViewController *sharedViewController = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedViewController = [[FooViewController alloc] init];
});
return sharedViewController;
}
你會那麼可以使用得到共享實例:
FooViewController *fooViewController = [FooViewController sharedViewController];
感謝您的意見。這當然是一個信息。我應該如何「重用」單身視圖控制器?如果我推動singleton viewcontroller,它會自動從導航堆棧中移除嗎? – eugene 2014-10-28 13:13:04
我不知道Android代碼的確切功能,所以我想我可能會理解你的問題是錯誤的。它是否創建一個活動的新實例並釋放舊實例?或者只保留一個可在任何地方使用的實例? – 2014-10-28 16:26:42
它保持單個實例。我不知道Android究竟如何做它的事情,雖然:( – eugene 2014-11-02 13:37:45