2010-12-14 54 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); ?

希望它有幫助。