开发者

iPhone: Is it Possible to Hide and Unhide UIACtionSheet Buttons?

I am using FBConnect in my app. The log in action sheet buttons are title "Log in Facebook" and "LogOut Facebook" but I want to display "Log into Facebook" and "Publish to Facebook". Currently, it looks like this...

alt text http://freezpic.com/pics/6944f45f17ba4bbb8220637d5a00a1c6.jpg

...but I want it to look like this...

alt text http://www.freezpic.com/pics/93f28f4f9103f0842c849d7daa644f81.jpg

... possibly set in these methods:

- (void)session:(FBSession*)session didLogin:(FBUID)uid {

    //Show button log out

}

- (void)sessionDidLogout:(FBSession*)session {

    //show button log in
}

Edit01- Alert sheet code from answer comment:

 -(IBAction)mySheet:(id)sender { 
    UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"FaceBook" 
                                                      delegate:sel开发者_StackOverflow中文版f 
                                             cancelButtonTitle:@"Cancel" 
                                        destructiveButtonTitle:nil 
                                             otherButtonTitles:@"Share On the Facebook" , 
                                                                @"Log in Facebook" ,
                                                                @"LogOut Facebook" ,nil]; 
    [menu showInView:self.view]; 
    [menu release]; 
}


Sure, just show a different UIActionSheet with just those two buttons depending on the state of the Facebook connection.

What about:

-(IBAction)mySheet:(id)sender
{
    if (alreadyLoggedInToFacebook) {
        UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"FaceBook"
            delegate:self  cancelButtonTitle:@"Cancel"
                destructiveButtonTitle:nil
                    otherButtonTitles: @"Share On the Facebook" ,  @"Log in Facebook" ,
                      @"LogOut Facebook" ,nil]; 
    } else {
        UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"FaceBook"
            delegate:self  cancelButtonTitle:@"Cancel"
                destructiveButtonTitle:nil
                    otherButtonTitles:  @"LogOut Facebook" ,nil]; 
    }
    [menu showInView:self.view]; 
    [menu release]; 
}


Finally i implement that ! (alreadyLoggedInToFacebook) must be (season.isConnect) . every thing is good ! but still a problem . after login - logout and share show great but didn't work great ! it means if user tap Logout button , login window appears again ! why ? i think , its because of FBLoginButton , when delet this method my UIActionSheet doesn't Show

! here is my code :

-(IBAction)mySheet:(id)sender
{
    if (session.isConnected) {
        UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"FaceBook"
                                                          delegate:self  cancelButtonTitle:@"Cancel"
                                            destructiveButtonTitle:nil
                                                 otherButtonTitles: @"Share On the Facebook" , @"Log out Facebook" ,nil]; 
        [menu showInView:self.view]; 
        [menu release]; 


    } else {



        UIActionSheet *menu2 = [[UIActionSheet alloc] initWithTitle:@"FaceBook"
                                                           delegate:self  cancelButtonTitle:@"Cancel"
                                             destructiveButtonTitle:nil
                                                  otherButtonTitles:  @"Log in Facebook" ,
                                nil]; 

        [menu2 showInView:self.view]; 
        [menu2 release]; 
    }
}


- (void)actionSheet:(UIActionSheet *)menu2 didDismissWithButtonIndex:(NSInteger)buttonIndex {

if (buttonIndex != [menu2 cancelButtonIndex]) 
    {

        FBLoginDialog* login = [[FBLoginDialog alloc] initWithSession:session];
        [login show];
        [login release];
    }

}

- (void)actionSheet:(UIActionSheet *)menu didDismissWithButtonIndex2:(NSInteger)buttonIndex {



    if (buttonIndex != [menu cancelButtonIndex]) 
    {
        [session logout];
    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜