Iphone弹出警报消息

Dev*_*Dev 18 iphone objective-c

我无处可寻.我不想每次都使用调试器.如何在iphone上获取打印消息.

Jas*_*ins 42

使用NSLog功能:

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

消息将写入控制台日志.您可以通过运行Console.app或将XCode切换到Debugger/Console视图在模拟器中查看它们(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];
Run Code Online (Sandbox Code Playgroud)

  • FYI UIAlertView现已被iOS 8弃用. (2认同)