aryDesc = [[NSMutableArray alloc]init];
NSMutableArray *ary_Temp ;
ary_Temp = [[NSMutableArray alloc]init ];
[ary_Temp addObject:@"Collins Burns"];
[ary_Temp addObject:@"cburns"];
[ary_Temp addObject:@"Active"];
[aryDescListing addObject:ary_Temp];
[ary_Temp removeAllObjects];
[ary_Temp addObject:@"Collins Burns"];
[ary_Temp addObject:@"cburns"];
[ary_Temp addObject:@"Active"];
[aryDescListing addObject:ary_Temp];
[ary_Temp removeAllObjects];
NSLog(@"ary Description===== >>>%@",aryDescListing);
我的代码如上所述我在日志中获得了两个对象,但两者都是空的我不知道要使用删除所有对象还是deryoc for ary_Temp。我应该使用removeAllobjects,或者每次将它添加到aryDescListing后分配它。 / p>
谢谢
答案 0 :(得分:1)
请勿使用dealloc
,而是使用release
。 dealloc
将取消分配对象而不计算其保留计数,它会迟早破坏您的应用。
也许你想要这个? :
aryDesc = [[NSMutableArray alloc] init];
NSMutableArray *ary_Temp ;
ary_Temp = [[NSMutableArray alloc] init];
[ary_Temp addObject:@"Collins Burns"];
[ary_Temp addObject:@"cburns"];
[ary_Temp addObject:@"Active"];
[aryDescListing addObject:ary_Temp];
[ary_Temp release];
ary_Temp = [[NSMutableArray alloc] init];
[ary_Temp addObject:@"Collins Burns"];
[ary_Temp addObject:@"cburns"];
[ary_Temp addObject:@"Active"];
[aryDescListing addObject:ary_Temp];
[ary_Temp release];
NSLog(@"ary Description===== >>>%@",aryDescListing);
BTW:removeAllObject
将从数组中删除对象(并将其retainCount
减少一个)但不会释放数组。