2011-09-03 23 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. –

相关问题