【问题标题】:Error presentViewController - view controllers adding - objective c错误 presentViewController - 添加视图控制器 - 目标 c
【发布时间】:2014-06-01 17:19:12
【问题描述】:

我有问题,不知道原因或解决方案 我有 AddDelegate 和另一个 ViewController,在这个 ViewController 中我添加了 FBFriendPickerViewController,ViewController 将被添加到 AppDelegate ..

我像这样将 ViewController 添加到 AppDelegate 中:(这个 ViewController 是 SocialSharing 类)

if( socialSharing == nil )
    socialSharing = [[SocialSharing alloc] init];

[_window.rootViewController.view addSubview:socialSharing.view];

并像这样在 ViewController(SocialSharing) 中添加 FBFriendPickerViewController:

-(void)shareOnFaceBook:(NSNotification *) notification
{
    if( shareOnUserOrFriendWallBtnIndex == 0 )
    {

    if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

        SLComposeViewController *facebookSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

        NSURL *candidateURL = [NSURL URLWithString:contentDataToShare];

        if (candidateURL && candidateURL.scheme && candidateURL.host) {
            [facebookSheet setInitialText:@"See this link .."];
            [facebookSheet addURL:candidateURL];
        }
        else // Event ***
        {
            [facebookSheet setInitialText:[NSString stringWithFormat:@"%@%@%@",[[appDelegate.extrasOverlayView.markerData.btnsArr objectAtIndex:0] objectForKey:@"markerName"],@" .. \n", contentDataToShare]];
            [facebookSheet addURL:[NSURL URLWithString:lastVideoLink]];
        }

        //Brings up the little share card with the test we have pre defind.
        [appDelegate.window.rootViewController presentViewController:facebookSheet animated:YES completion:nil];

    } else {
        //This alreat tells the user that they can't use built in socal interegration and why they can't.
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry" message:@"You can't send a tweet right now, make sure you have at least one Facebook account setup and your device is using iOS." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
    }

}
else if( shareOnUserOrFriendWallBtnIndex == 1 )// post on friend's wall
{
    if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]] )
    {
        NSLog(@"Facebook is inastalled on this device.");
        if( friendPickerController == nil )
        {
            friendPickerController = [[FBFriendPickerViewController alloc] init];
            friendPickerController.delegate = self;

            if( !( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone ) )
                friendPickerController.title = @"Select Friends";
        }

        [friendPickerController loadData];


        // Present view controller modally
        [self presentViewController:friendPickerController animated:YES completion:nil];

    }
    else{
        NSLog(@"This device has no Facebook app.");
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry" message:@"You can't invite friends, Facebook app isn't installed, please install it and retry again." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
    }

}

}

并从 SocialSharing 中解散friendPickerController,例如:

- (void)facebookViewControllerCancelWasPressed:(id)sender
{
    NSLog(@"Friend selection cancelled.");
    [self dismissViewControllerAnimated:YES completion:nil];
}

我用过:

[friendPickerController dismissModalViewControllerAnimated:YES];
   OR //[self.view.window.rootViewController dismissViewControllerAnimated:YES completion:Nil];
OR //[self dismissModalViewControllerAnimated:YES];

它只在第一次运行良好,一次,friendPickerController 出现并在关闭时关闭,但是当再次调用打开时,我有这个错误:

“线程 1:信号 SIGBRT”

FOR 行:

[self presentViewController:friendPickerController animated:YES completion:nil];

注意:当我直接在 AppDelegate 上添加friendPickerController(在 AppDelegate 的类中)而不使用另一个类(这里是 SocialSharing ViewController)时,效果很好..

我正在开发 IOS 7 和 Facebook SDK 3.13.. 那么,问题是什么,我该如何解决呢?

谢谢

【问题讨论】:

  • 第二次尝试显示friendPickerController是否不为零?
  • 每次朋友选择器对象都有价值,所以它不会再次出现。为此,在您的视图中为朋友选择器创建对象加载或为零您的对象以处理更多时间
  • @Zhang,谢谢回复,我已经通过if(friendPickerController == nil)检查是否为nil,每次都会调用这段代码来显示它
  • @karthikeyan,谢谢您的回复,“每次朋友选择器对象都有价值,所以它不会再次出现”是什么意思?你的意思是什么价值?,还有,你的意思是我应该每次都设置friendPickerController = nil并重新分配和初始化来呈现它吗?
  • 向我展示您的按钮单击的完整代码。如果您在按钮单击中执行此操作,第一次只有 nil if(friendPickerController == nil) 行。下次这种情况将不成立。跨度>

标签: ios objective-c facebook uiviewcontroller


【解决方案1】:

我做了什么来解决我的问题,我在 NORMAL CLASS 中创建了friendPickerController,而不是 ViewController,并将其添加到 AppDelegate

     [appDelegate.window.rootViewController presentViewController:friendPickerController animated:YES completion:nil];

并通过以下方式解雇:

    [appDelegate.window.rootViewController dismissViewControllerAnimated:YES completion:nil];

并像这样调用这个类:

if( socialSharing == nil )
{
    socialSharing = [[SocialSharingClass alloc] init];
    [socialSharing initSocialSharing];
}

不过,我不知道问题所在,但这解决了它。希望对任何人都有帮助。

【讨论】:

    猜你喜欢
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-18
    相关资源
    最近更新 更多