简体   繁体   English

performeguewithidentifier在IBAction方法中不起作用

[英]performseguewithidentifier not working in IBAction method

I have a storyboard with a segue connected between to views and the following code. 我有一个故事板,在视图和以下代码之间连接了segue。 For some reason the segue isn't being called and I am positive it is named correctly. 由于某种原因,未调用segue,我肯定它的名称正确。 I am wondering if it dosen't work because it is in an IBAction method or what. 我想知道它是否无效,因为它在IBAction方法中或什么。 I am very confused so let me know if you have any ideas. 我很困惑,如果您有任何想法请告诉我。 thanks. 谢谢。

-(IBAction)didPressSubmit:(id)sender{

    NSString *idOfObject = [[NSUserDefaults standardUserDefaults] objectForKey:@"idOfObject"];


    PFQuery *query = [PFQuery queryWithClassName:@"RequestsClass"];


    [query getObjectInBackgroundWithId:idOfObject block:^(PFObject *myObj, NSError *error) {

        myObj[@"hasResponded"] = @"has";
        myObj[@"answer"] = textField.text;
        [myObj saveInBackground];



    }];

        [self performSegueWithIdentifier:@"userDidRespond" sender:self];
}

Also there are no errors just nothing happens. 也没有错误,只是什么也没有发生。 I added an NSLog right above the line that calls it saying "about to perform segue" and it printed fine. 我在该行上方添加了一个NSLog,称其为“即将执行隔离”,并且打印良好。 So I'm not sure. 所以我不确定。

I am also getting this warning 我也收到这个警告

Warning: A long-running Parse operation is being executed on the main thread. 
 Break on warnParseOperationOnMainThread() to debug

So i maybe i need to Deque main thread or something like that? 所以我也许我需要Deque主线程或类似的东西? Thanks 谢谢

Move this line : 移动这一行:

[self performSegueWithIdentifier:@"userDidRespond" sender:self];

inside the block. 在块内。

Like this : 像这样 :

-(IBAction)didPressSubmit:(id)sender{

NSString *idOfObject = [[NSUserDefaults standardUserDefaults] objectForKey:@"idOfObject"];


PFQuery *query = [PFQuery queryWithClassName:@"RequestsClass"];


[query getObjectInBackgroundWithId:idOfObject block:^(PFObject *myObj, NSError *error) {

    myObj[@"hasResponded"] = @"has";
    myObj[@"answer"] = textField.text;
    [myObj saveInBackground];

    [self performSegueWithIdentifier:@"userDidRespond" sender:self];

}];

}

I hope this will do the trick. 我希望这可以解决问题。

you can also navigate from one view controller to another by following code without using performSegueWithIdentifier method. 您还可以通过以下代码从一个视图控制器导航到另一个视图控制器,而无需使用performSegueWithIdentifier方法。

 UIStoryboard *story = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
 viewController *viewObj = [story instantiateViewControllerWithIdentifier:@"viewController"];

 [self.navigationController pushViewController:viewObj animated:YES];

For this you have to give storyboardID to viewcontroller as "viewController" in your storyboard. 为此,您必须在情节提要中将StoryboardID作为“ viewController”提供给viewcontroller。 And by this method you can also set objects for next view. 通过这种方法,您还可以为下一个视图设置对象。

The Parse warning you are getting is unrelated and should go in a different question. 您收到的“解析”警告是无关的,应该输入另一个问题。 It is telling you that you are trying to connect to Parse (maybe a login in?) on the main thread. 它告诉您您正在尝试连接到主线程上的Parse(也许是登录名?)。 You want to do this asynchronously on a different thread with a completion block. 您想在另一个带有完成块的线程上异步执行此操作。

Something like this: (in SWIFT) 像这样:(在SWIFT中)

PFUser.logInWithUsernameInBackground(userName.text, password: passwordField.text, block: {
        (user,error) in
        completion(error == nil)
    })

Parse has many examples in Objective-C as well. 解析在Objective-C中也有很多示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM