如何从 ViewController 获取返回值? // popViewControllerAnimated 两次?双背?

发布于 2024-12-02 22:22:05 字数 410 浏览 1 评论 0原文

我已经包含了 Three20 库并使用 TTNavigator 来表达我的观点。

我的目标是从视图 4 翻转回视图 2。

我找到的唯一解决方案是在视图 4 中调用 popViewControllerAnimated 以到达视图 3,然后在视图 3 的 ViewDidAppear 中再次调用 popViewControllerAnimated 以到达视图2.

问题是,当然,我只想在View 3 ViewDidAppear中调用popViewControllerAnimated,当ViewDidAppear从View 4调用到View 3时,而不是在其他情况下(例如,视图 2 打开视图 3)。

据我所知,我必须设置一个 BOOL 属性或类似的东西,但是如何设置呢? 由于 Three20 提供的 URL 导航,我无法在这里与代表一起工作。

I have included the Three20 Library and use the TTNavigator for my views.

My goal is to flip from view 4 back to view 2.

The only solution I found for this, is to call popViewControllerAnimated in View 4 to get to View 3, then in the ViewDidAppear in view 3 call the popViewControllerAnimated again, to get to View 2.

Problem is, of course, I only want to call the popViewControllerAnimated in View 3 ViewDidAppear only, when the ViewDidAppear is called from View 4 to View 3, not in other cases (e.g. View 2 opens View 3).

So as far as I see I have to set a BOOL property or something like this, but how?
I can't work with delegates here, because of the URL-Navigation given by Three20.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南笙 2024-12-09 22:22:05

使用 UINavigationController< /a> 的 -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];
}

Use UINavigationController's -popToViewController:animated: method:

// 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];
}
云雾 2024-12-09 22:22:05

使用 Singleton 设计模式怎么样?

您可以在其中设置一个布尔值,您可以根据您来自哪个视图来更改该布尔值,然后在视图 3 中检查该值是什么。 情况下执行此操作的最简单方法。

在我看来,这是在不使用 delegates .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;
    }
}

如果代码中存在一些小错误,请原谅我,我很快就想到了。

What about using the Singleton design pattern

You can set a bool in there that you can change depending from which view you are coming and then in view 3 check what that value is. In my opinion its the easiest way of doing this without using the delegates

.h file

@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;
    }
}

Forgive me if there is some small mistake in the code, did it out the top of my head real quick.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文