2010-09-10 65 views
0

任何人都可以告訴我爲什麼記錄[self.giftees count]一直返回0,即使我將對象添加到它?NSMutableArray addObject不影響計數?

頭:

#import <UIKit/UIKit.h> 

@interface Test2AppDelegate : NSObject <UIApplicationDelegate> 
{ 
    UIWindow *window; 
    NSMutableArray *giftees; 
} 

@property (nonatomic, retain) UIWindow *window; 
@property (nonatomic, retain) NSMutableArray *giftees; 

@end 

從didFinishLaunchingWithOptions稱爲:

- (void)bootstrapGiftees 
{ 
    NSArray *gifteeNames = [NSArray arrayWithObjects:@"Jesse",,nil]; 

    for (NSString *gifteeName in gifteeNames) 
    { 
     GifteeModel *g = [[GifteeModel alloc] init]; 
     g.name = gifteeName; 

     [self.giftees addObject:g]; 
     NSLog(@"giftees count = %d", [self.giftees count]); 
     [g release]; 
} 
} 

回答

6

是 「禮品接收者」 初始化?如果它爲零,[giftees count]也將返回0

2

因爲你很可能從來沒有初始化giftees數組,所以它仍然是零代碼運行時。

+0

非常感謝Eiko – 2010-09-13 06:26:51

相關問題