Iphone 将对象添加到不同类中的NSMutableArray
我有一个类SplitMonths和January,使用这个类SplitMonths,我尝试在类January中的NSMutableArray中存储对象,但是我似乎无法让它工作 六个月Iphone 将对象添加到不同类中的NSMutableArray,iphone,objective-c,class,object,nsmutablearray,Iphone,Objective C,Class,Object,Nsmutablearray,我有一个类SplitMonths和January,使用这个类SplitMonths,我尝试在类January中的NSMutableArray中存储对象,但是我似乎无法让它工作 六个月 @class January; @interface ... { NSMutableArray * calEvents; January *janClass; } -(void)separate; @property (nonatomic, assign) January *janClass; 好几
@class January;
@interface ... {
NSMutableArray * calEvents;
January *janClass;
}
-(void)separate;
@property (nonatomic, assign) January *janClass;
好几个月了
#import "January.h"
@implementation SplitMonths
@synthesize janClass;
-(void)viewDidLoad{
[super viewDidLoad];
janClass = [[January alloc]initWithNibName:@"January" bundle:nil];
janClass.JanEvents = [[NSMutableArray alloc]init];
n=0;
}
....REST OF CODE...Loading stuff into calEvents.
-(void)separate{
int incrS = 0;
while (incrS < [calEvents count]){
if ([monthString rangeOfString:@"Jan"].location == NSNotFound){
}else{
[[janClass JanEvents] addObject:[calEvents objectAtIndex:incrS]];
NSLog(@"STORY ADDED");
}
NSLog(@"ARRAY:%@",janClass.JanEvents);
incrS = incrS + 1;
}
[janClass.JanEvents release];
NSLog(@"COUNT:%d",[janClass.JanEvents count]);
}
一月
@synthesize JanEvents;
Add I checked和calEvents确实包含包含@“Jan”的对象,我使用断点测试过,它们不会添加到nsmutablearray。您有几个内存管理问题。但首先,您是否在日志中看到“添加的故事”?您可以显示日志输出吗?2011-12-24 13:24:10.628[1377:15803]添加的故事2011-12-24 13:24:12.358[1377:15803]MONTHSTRING:(null)此MONTHSTRING日志行在代码中的何处?数组:line发生了什么?我不小心重命名了它,MONTHSTRING是数组,所以数组是(null)
@synthesize JanEvents;