2010-12-14 60 views
1

我一直在构建一个相当复杂的系统,现在有了我想要更简洁的调试的时间。我想在通知窗口中显示变量的内容(在本例中为NSString,名称为v_string)(您收到短信时出现的那种窗口)。iPhone:使用警报帮助调试

有没有简单的方法来调用一个变量的警报?

由于事先

回答

3

NSLog没有做?如果没有(例如,如果你需要调试断开连接的设备上运行的应用程序),可以延长UIAlertView与类别:

@implementation UIAlertView (Logging) 

+ (void) log: (id <NSObject>) anObject 
{ 
    NSString *message = [anObject description]; 
    UIAlertView *alert = [[self alloc] initWith…]; 
    [alert show]; 
    [alert release]; 
} 

然后在代码:

NSString *anInterestingString = …; 
[UIAlertView log:anInterestingString]; 
0

当您生成字符串显示在警报窗口中,只需使用stringByAppendingString附加变量的字符串表示。

0

警报窗口很麻烦。使用NSLog代替:

NSLog(@"Variable is: %@", v_string); 

而在Xcode的控制台中,您将看到该文本。

0
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"My Debug String" message:v_string delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
[message show]; 
[message release]; 

我想这样你就可以看到你想要的东西。但是,正如zoul所说,为什么不使用NSLog(@“my var:%@”,v_string); ?

希望它有帮助。