iOS按钮执行多个操作

时间:2013-09-10 07:43:17

标签: ios facebook storyboard segue

我在指南的末尾有一个按钮,表示完成!我需要它来显示Facebook发布对话并且还要回到菜单屏幕

目前,我打开了一个Facebook发布屏幕,当您点击发布或取消时,该屏幕会弹出并返回。我想在facebook流程完成后返回菜单。我已经按照编程方式跟踪了一个指南,并将代码添加到我当前的postToFacebook IBAction中,但它没有用。然后我尝试创建它自己的IBAction并将其链接到按钮,但它也没有工作。 在Facebook对话之后,有谁知道我怎么能让它变得孤立无援 如果你需要,请提供我的Facebook发布代码

- (IBAction)PostToFacebook:(id)sender {
mySLComposerSheet = [[SLComposeViewController alloc] init];
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[mySLComposerSheet setInitialText:@"I just followed a guide on this App - Get it on the App Store http://"];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
}

继承了程序设计的代码

-(IBAction)nextView{
[self performSegueWithIdentifier:@"next" sender:self];   }

2 个答案:

答案 0 :(得分:0)

您可以将所有代码放在一个-(IBAction)中,并使用一个布尔值,在执行Facebook操作后更改其值。

像这样,

- (IBAction)PostToFacebook:(id)sender {
    if(valueOfBoolean==TRUE){
        mySLComposerSheet = [[SLComposeViewController alloc] init];
        mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
        [mySLComposerSheet setInitialText:@"I just followed a guide on this App - Get it on the App Store http://"];
        [self presentViewController:mySLComposerSheet animated:YES completion:nil];
        valueOfBoolean=FALSE;
    }
    else{
        [self performSegueWithIdentifier:@"next" sender:self];
    }
}

valueOfBoolean方法中将TRUE的默认值设为viewDidLoad

答案 1 :(得分:0)

已编辑:

   - (IBAction)facebook:(id)sender {


    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
        SLComposeViewController *facebook = [[SLComposeViewController alloc]init];

        facebook = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
        [facebook setInitialText:[NSString stringWithFormat:@"your string"]];
        [self presentViewController:facebook animated:YES completion:nil];

        [facebook setCompletionHandler:^(SLComposeViewControllerResult result){
            NSString *output;
            switch (result) {
                case SLComposeViewControllerResultCancelled:
                    // here you can handle your seque, or your custom action what you want
                    break;
                case SLComposeViewControllerResultDone:
                    // here you can handle your seque, or your custom action what you want
                    break;
                default:
                    break;
            }
            //            [self dismissViewControllerAnimated:YES completion:nil];

        }];
    }
    else{
        UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"No Facebook Account" message:@"There are no Facebook accounts configured. You can configure or create accounts in settings ." delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
        [alertView show];
    }

}

我希望它有所帮助!