2009-10-01 193 views

回答

41

使用的NSLog功能:

NSLog(@"Your message here."); 
// with parameters: 
NSString * myParam = @"Some value"; 
NSLog(@"myParam:%@", myParam); 

這些消息被寫入到控制檯日誌。您可以在模擬器上運行Console.app或通過切換到的XCode調試器/控制檯視圖(XCode -> Run -> Console)

查看他們,如果你真的想做一個彈出警報(如JavaScript的alert()功能),你可以這樣做:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Test Message" 
                message:@"This is a sample" 
               delegate:nil 
             cancelButtonTitle:@"OK" 
             otherButtonTitles:nil]; 
[alert show]; 
[alert release]; 
+2

僅供參考UIAlertView中現在已經過時,與iOS 8 – 2015-02-13 00:15:58

+1

的例子,如何用新的''UIAlertController一個可以代替'UIAlertView'在這裏找到:http://useyourloaf.com/blog/2014/09/05/uialertcontroller-changes-in-ios-8.html – andi 2015-08-08 15:19:52

+0

或官方文檔:https:// developer .apple.com/library/ios/documentation/UIKit/Reference/UIAlertController_class/index.html#// apple_ref/occ/cl/UIAlertController – andi 2015-08-08 15:30:24

1

使用Google或Xcode文檔查看器查找UIAlertView

3
UIAlertView* alert; 
alert = [[UIAlertView alloc] initWithTitle:@"Info" message:@"Much more info" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
[alert show]; 
[alert release]; 
4
// open a alert with an OK and cancel button 
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView" 
     message:@"My message" delegate:self cancelButtonTitle:@"Cancel" 
     otherButtonTitles:@"OK", nil]; 
[alert show]; 
[alert release]; 

樣品圖片:

enter image description here

+0

就像一個魅力。 UPVOTED! :) – 2013-05-17 16:55:39

+0

謝謝託尼吉爾 – 2014-06-18 13:38:21