2015-07-20 61 views
0

這幅畫應該說夠了: enter image description here雨燕2.0沒有讓我UIAlertAction

我一直在網上淘來尋找答案,沒有其他人似乎也有這個問題。我正在用Swift 2使用Xcode 7 Beta 3。我無法弄清楚什麼是錯的。

在此先感謝

編輯:

下面的代碼:

func input(text:String) -> String { 
    Say(text) 
    let alert:UIAlertController = UIAlertController(title: "Goog", message: text, preferredStyle: UIAlertControllerStyle.Alert) 
    [alert .addTextFieldWithConfigurationHandler({ (textfield: UITextField!) -> Void in 
    })] 
    var returnValue:String = "" 
    let confirmAction = UIAlertAction(
     title: "OK", style: UIAlertActionStyle.Default) {(action) in 
      returnValue = (alert.textFields[0] as UITextField).text! 
      return 
    } 
    return returnValue 
} 
+0

顯示更多的代碼,我們也許能夠更好地解決你的問題。 (定義了什麼'returnValue'?它的類型是什麼?)並且將你的代碼作爲文本發佈,而不是Xcode屏幕截圖。並非每個人都以某種方式使用SO,以便他們輕鬆讀取嵌入圖像中的文本。 – rickster

+0

就在我定義動作之前。我簡單地說:var returnValue:String =「」 –

+1

這個錯誤往往是誤導。您應該在此代碼段前後顯示5行(請以文本形式)。 – Mundi

回答

-1

您要使用的斯威夫特枚舉的動作風格是這樣的:

let alertAction2 = UIAlertAction(title: "My Alert", style: .Default) 
     {(action:UIAlertAction) -> Void in 
      // do something with action 
      return 
     } 

或者更簡潔:

let alertAction2 = UIAlertAction(title: "My Alert", style: .Default) 
     {action in 
      // do something with action 
     } 
+1

讓012 confirm_ction = UIAlertAction( title:「OK」,style:UIAlertActionStyle.Default){(action)in returnValue =(alert.textFields [0] as UITextField).text! return } return returnValue –

+0

哦,我忘了標籤@PaulRobinson –

+0

你不能從處理程序返回任何東西,因爲它返回Void。你所能做的只是做一些事情。我是否正確理解您的評論@NerdyLimeApps? – pxr

-1
UIAlertController *altSuccess = [UIAlertController alertControllerWithTitle:@"Success" message:@"Login Successfully" preferredStyle:UIAlertControllerStyleAlert]; 

UIAlertAction *okSuccess = [UIAlertAction 
            actionWithTitle:@"OK" 
            style:UIAlertActionStyleDefault 
            handler:^(UIAlertAction * action) 
            { 
             NSLog(@"%@",[dict objectForKey:@"email"]); 
             NSLog(@"%@",[dict objectForKey:@"password"]); 
             [altSuccess dismissViewControllerAnimated:YES completion:nil]; 
            }]; 

     [altSuccess addAction:okSuccess]; 

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

它的正常工作......

+1

最初的問題是關於在Swift中使用UIAlertAction。問題的標籤和標題甚至包含「Swift」這個詞。 你的答案在Objective-C中。 –