2014-04-28 18 views
0

我需要添加一個按鈕Facebook,然後該操作應該將用戶帶到Facebook,我只是不確定如何從下面的代碼中執行操作?如何在uiAlert上添加另一個將用戶導向Facebook的按鈕?

-(IBAction)btContinueClick:(id)sender{ 

    if(Level == [list count]){ 

     UIAlertView *info = [[UIAlertView alloc]initWithTitle:@"Good" message:@"Go to facebook?" delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"Facebook"]; 
     [info show]; //// Change Game End Message 
    } 
} 
+0

使用委託方法你想去Facebook應用程序,或在瀏覽器中打開Facebook的? –

+0

應用程序,謝謝 – user3580117

回答

0

確保你在.h文件中

-(IBAction)btContinueClick:(id)sender{ 
if(Level == [list count]){ 


    UIAlertView *info = [[UIAlertView alloc]initWithTitle:@"Good" message:@"Go to facebook?" delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"Facebook"]; 
    [info show]; //// Change Game End Message 
    info.delegate=self; 

} 
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex]; 

    if(buttonIndex==1) 
    { 
     NSLog(@"Facebook selected."); 
     NSURL *url = [NSURL URLWithString:@"fb://profile/<id>"]; // provide the app ID 
     [[UIApplication sharedApplication] openURL:url]; 


    } 
} 
+0

像這樣:@interface ViewController:UIViewController - ? – user3580117

+0

@interface PlayViewController:UIViewController user3580117

+0

right ........... – Vizllx

1

如果你想要去的Facebook的iOS中的本機應用程序添加UIAlertViewDelegate。的alertView

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 

    if(buttonIndex == 1) { 
    NSURL *url = [NSURL URLWithString:@"fb://profile"]; 
    if ([[UIApplication sharedApplication] canOpenURL:url]) { //USE FB NATIVE APP 
     [[UIApplication sharedApplication] openURL:url]; 
    } 
    else { //IF THE DEVICE IS UNABLE TO OPEN IN NATIVE APP, USE BROWSER INSTEAD 
     NSURL *browserURL = [NSURL URLWithString:@"http://www.facebook.com"]; 
     [[UIApplication sharedApplication] openURL:browserURL]; 
    } 
    } 
} 
相關問題