2009-10-20 30 views
0

嗨夥計,這是jagadeesh,一邊練習應用程序,參照該平臺的IM初學者一些書,我的應用程序運行Suceessfully但在控制檯無輸出顯示這裏是我的申請#進口關於在Xcode調試

@interface ClassA : NSObject 

{ 
    int x; 
} 

-(void) initVar; 
@end 

@implementation ClassA 
-(void) initVar 
{ 
    x = 100; 
} 

@end 
@interface ClassB : ClassA 
{ 
    int y; 
} 

-(void) initVar; 
-(void) printVar; 

@end 

@implementation ClassB 
-(void) initVar 
{ 
    x = 200; 
    y = 300; 
} 
- (void) printVar 
{ 
    NSLog(@"x= %i", x); 
    NSLog(@"y= %i", y); 
} 

@end 

int main (int argc, const char * argv[]) { 
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 

    ClassB *b = [[ClassB alloc] init]; 
    [b initVar]; 
    [b printVar]; 
    [b release]; 
    [pool drain]; 
    return 0; 
} 

和****控制檯信息是這樣的**** 程序加載。 運行 [切換處理1310本地線程0x2e03] 運行... (GDB)

+0

在一個不相關的說明中,您應該避免訪問子類的方法(如ClassB的'-initVar')中父類的成員變量(例如'x')。相反,爲設置成員的父代創建init和accessor方法,並調用子進程的方法。使用ObjC 2.0,您可以使用屬性:http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocProperties.html – outis 2009-10-20 09:35:13

回答

1

的代碼運行正常。如果你沒有收到任何消息,那很可能是你無意中在GDB中設置了一個斷點。 在這種情況下,在「(GDB)」提示符下鍵入「信息斷點」將告訴他們:

(gdb) info breakpoints 
Num Type   Disp Enb Address What 
1 breakpoint  keep y 0x000027de in -[SMStatisticController init] at SMStatisticController.m:44 
    breakpoint already hit 1 time 
Current language: auto; currently objective-c 
(gdb) 

要刪除所有斷點做「DEL」刪除斷點和「c」繼續執行:

(gdb) del 
(gdb) c 
+0

感謝Diclu現在可以正常工作了非常感謝您的寶貴建議 – user185590 2009-10-20 09:27:39