Iphone弹出警告消息

Iphone弹出警告消息,iphone,objective-c,Iphone,Objective C,我到处都找不到这个。我不想每次都使用调试器。如何在iphone上获取打印消息。使用NSLog功能: NSLog(@"Your message here."); // with parameters: NSString * myParam = @"Some value"; NSLog(@"myParam:%@", myParam); 消息将写入控制台日志。通过运行Console.app或将XCode切换到调试器/控制台视图(XCode->Run->Console) 如果您确实想执行弹出警报(如j

我到处都找不到这个。我不想每次都使用调试器。如何在iphone上获取打印消息。

使用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];

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

UIAlertView* alert;
alert = [[UIAlertView alloc] initWithTitle:@"Info" message:@"Much more info" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[alert release];
示例图像:


仅供参考,iOS 8现在不推荐使用UIAlertView。有关如何用新的
UIAlertController
替换
UIAlertView
的示例,可以在此处找到:或在官方文档中找到:
// 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];