2010-09-10 68 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

相关问题