iphone - 以编程方式调用 segue 不起作用

标签 iphone ios ios5

如果用户第一次使用我的应用程序,我正在尝试打开一个特殊的 viewController。我以前在其他情况下也可以使用它,但由于某种原因,它现在不起作用。我尝试了两种不同的方法,但都没有奏效。我尝试的第一件事是直接从 appDelegate 检查并执行它...然后我尝试检查它是否是第一次从 Root View Controller viewDidLoad 方法,以及它是否是第一次调用序列以打开特殊注册页面. Niether 正在工作,我不知道为什么.....这是我正在使用的一些代码:

这是在 Root View Controller 内部。当我这样做时,它会在日志上打印出“主要是第一次”,所以我知道它正在那里。我仔细检查了 Storyboard 中的segue,它被正确命名并往返于正确的地方......

- (void)viewDidLoad
{
    [super viewDidLoad];

    appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    if([appDelegate firstTime])
    {
    [self performSegueWithIdentifier:@"mToRegister" sender:self];
        NSLog(@"Main is First time");
    }
    // Do any additional setup after loading the view.
}

在 appDelegate 内部:

NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
BOOL hasused = [standardUserDefaults boolForKey:@"haveused"];
if(haveused){       
    //NOT THEIR FIRST TIME
    //Handle scenario
    firstTime = NO;

    NSString* guid = [[NSMutableString alloc]initWithString:[self getMacAddress]];
    //interest = [appDelegate interest];

    NSString *splitter = [[NSString alloc]initWithString:@"&"];
    NSMutableString *post = [[NSMutableString alloc]initWithString: @"user_read=1&guid="];
    [post appendString:guid];
    NSLog(@"String for Post is %@", post);
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setValue:@"Basic ==" forHTTPHeaderField:@"Authorization"];
    [request setURL:[NSURL URLWithString:@"http://something.com/app/usercrud.php"]];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];

    theConnection = [[NSURLConnection alloc]initWithRequest:request delegate:self];
}
else {
        NSLog(@"This is the First time");
        firstTime = YES;
        //THEIR FIRST TIME
        //Handle scenario



//        UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone"
//                                                                 bundle: nil];
//        
//        UIViewController *controller = (UIViewController*)[mainStoryboard 
//                                                           instantiateViewControllerWithIdentifier: @"register"];
//        UIViewController *root = (UIViewController *)self.window.rootViewController;
//        [root presentModalViewController:controller animated:YES]; 
        [self.window.rootViewController performSegueWithIdentifier:@"mToRegister" sender:self];        

    }

任何想法为什么它不会工作?如果没有人知道处理这种情况的更好方法吗?

最佳答案

我的事情是你的应用程序委托(delegate)没有得到适当的管理,使用 NSDefaults 来存储任何唯一的身份并在下次启动时检查,如果 NSDefaults 中存在,那么这不是第一次,如果它不存在,则不是第一次。测试是否存在,如果仍然存在 prblm,那么也从应用程序委托(delegate)中发布您的 if 部分

关于iphone - 以编程方式调用 segue 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10466526/

相关文章:

iphone - 如何将 url 中的图像保存到应用程序中?

android - 在 AmfPHP 中开发的 Web 服务——在 IOS 和 Android 中使用?

iphone - iPhone 5 设计将使用自动调整大小蒙版?

ios - 如何使对象免于 SKcameranode 移动

iphone - Objective-C 弧错误 : -fobjc-arc is not supported with fragile abi

iphone - 奇怪的 UIImageview 远程图像加载行为

ios - iPhone - 从 UILabel 中的链接中删除下划线

iphone - 在方法中运行时,从 nib 加载的 View 不会更新 UILabel 的内容

iphone - 检测硬件类型、iPhone 4 或 iPhone 5 的最佳方法?

iphone - [UIViewController 哈希] : message sent to deallocated instance with ARC