【问题标题】:How to get a "first time open"-view for my app?如何为我的应用程序获得“首次打开”视图?
【发布时间】:2010-01-04 01:36:59
【问题描述】:

我正在尝试找到一种方法,让我的程序在您首次启动应用程序时显示“设置”视图,但它不起作用。

这是我的尝试。如果程序第一次打开 (abfrage = false),appdelegate 应该查看并打开另一个视图。

#import "TweetButtonAppDelegate.h"
#import "TweetButtonViewController.h"
#import "BenutzerdatenViewController.h"

@implementation TweetButtonAppDelegate

@synthesize window;
@synthesize viewController;
@synthesize abfrage;


- (void)applicationDidFinishLaunching:(UIApplication *)application {
    abfrage = FALSE;
if (abfrage == TRUE) {
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
} else {
    BenutzerdatenViewController *Benutzerdaten = [[BenutzerdatenViewController alloc] initWithNibName:nil bundle:nil];
    [Benutzerdaten release];}
}
(...)

我尝试在 appdelegate 中构建一个 if-query,但总是当“abfrage”为 false 时,程序只会加载一个白色视图。

【问题讨论】:

    标签: iphone objective-c xcode


    【解决方案1】:

    试试这个在“顶级”视图控制器中实现的:

    - (void)viewDidAppear:(BOOL)animated {
        [flasher setSettingsFromModel:self.settingsModel];
        if (self.settingsModel.warningAccepted == NO) {
            [self showWarning];
            [flasher setFlashingEnabled:NO];
        } else
            [flasher setFlashingEnabled:YES];
        [super viewDidAppear:animated];
    }
    
    ...
    
    - (void)modalViewControllerDidFinish:(UIViewController *)controller {
            if (self.settingsModel.warningAccepted == YES)
                [flasher setFlashingEnabled:YES];
            [self dismissModalViewControllerAnimated:YES];
    }
    
    ...
    
    - (void)showWarning {
            WarningViewController *controller = [[WarningViewController alloc]
                            initWithNibName:@"WarningView" bundle:nil];
            controller.delegate = self;
            controller.settingsModel = settingsModel;
                controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
            [self presentModalViewController:controller animated:YES];
            [controller release];
    }
    

    基本上我认为您想在主视图控制器的 viewDidAppear 中执行此操作。至少我是这样做的。

    【讨论】:

    • 我不知道为什么,但是如果我在 ViewDidAppear 或 viewDidLoad 中设置它,我的 ViewController 不会加载新视图 - 我知道,我的代码是正确的,因为当我UIAction 的代码,他通过按下按钮加载新视图。
    【解决方案2】:

    我得到了一个解决方案,可以在AppDelegate的applicationDidFinishLaunching中设置:

    - (void)applicationDidFinishLaunching:(UIApplication *)application {
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
        NSString *firsttime = [defaults stringForKey:@"firsttime"];
        if (firsttime == nil) {
    
            TheOtherViewController *Other = [[TheOtherViewController alloc] initWithNibName:nil bundle:nil];
            Other.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
            [window addSubview: Other.view];        
    
            [defaults setObject:@"lasttime" forKey:@"firsttime"];
        }   else {  [window addSubview:viewController.view];
            [window makeKeyAndVisible];
        }
    }
    

    【讨论】:

      【解决方案3】:

      问题是你初始化了一个新的BenutzerdatenViewController,但没有将它添加到窗口中。

      你需要在初始化之后添加:

      [window addSubview: Benutzerdaten.view];
      [window makeKeyAndVisible];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-30
        相关资源
        最近更新 更多