2011-09-03 31 views
0

我已經包含了Three20庫,並使用TTNavigator作爲我的觀點。如何從ViewController獲取返回值? // popViewControllerAnimated兩次?雙後退?

我的目標是從視圖4回翻轉查看2.

我發現唯一的解決方法,是考慮到3個呼叫呼叫popViewControllerAnimated在View 4去查看3,然後在ViewDidAppear popViewControllerAnimated再次獲取到視圖2.

問題是,當然,我只想在View 3 ViewDidAppear中調用popViewControllerAnimated,當ViewDidAppear從視圖4調用到視圖3時,不在其他情況下例如View 2打開View 3)。

所以據我看到我必須設置一個布爾屬性或類似的東西,但如何? 由於Three20給出的URL導航,我無法在這裏與代表一起工作。

回答

3

使用UINavigationController-popToViewController:animated:方法:

// This is a method of your UIViewController subclass with view 4 
- (void) popTwoViewControllersAnimated:(BOOL)animated { 
    NSInteger indexOfCurrentViewController = [self.navigationController.viewControllers indexOfObject:self]; 
    if (indexOfCurrentViewController >= 2) 
     [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:indexOfCurrentViewController - 2] animated:animated]; 
} 
+1

我確實認爲這是比我更好的解決方案。 – Armand

+0

完美地工作 – Kovu

1

怎麼樣使用Singleton設計模式

您可以設置一個布爾值,在那裏,你可以根據從中查看您來了,然後在視圖3檢查值是什麼改變。在我看來,它這樣做不使用代表

.h文件中

@interface Singleton : NSObject 
{ 
    BOOL flag; 
} 

@property(nonatomic) BOOL flag; 
@end 


.m file 

static Singleton *instance = nil; 
@implementation Singleton 
@synthesize flag; 
+(id) sharedManager 
{ 
    @synchronized(self){ 
     if(instance == nil) 
      instance = [[super allocWithZone:NULL] init]; 
    } 
    return instance; 
} 

+(id)allocWithZone:(NSZone *)zone 
{ 
    return [[self sharedManager] retain]; 
} 

-(id) copyWithZone:(NSZone *)zone 
{ 
    return self; 
} 

-(id) retain 
{ 
    retrun self; 
} 

-(unsigned) retainCount 
{ 
    retrun 1; 
} 

-(id) init 
{ 
    if(self == [super init]) 
    { 
     flag = NO; 
    } 
} 

的最簡單的辦法原諒我,如果有在代碼中的一些小錯誤,這樣做是出於我的頭頂真正的快。

+0

這是一個非常糟糕的解決上述問題。 –

+0

@Fabian你有什麼建議呢?我從來沒有使用過單身存儲只有1個值,我通常在我的單身存儲信息大量 – Armand

+0

請參閱我的答案下面。我不認爲單身人士總體上不好,但你不需要爲這個問題存儲一個BOOL值。如果你必須存儲這些信息,Singleton並不是一個好習慣。然後你會在視圖控制器中存儲一個BOOL標誌,其視圖爲3. –

相關問題