在不同的类中将对象添加到NSMutableArray

时间:2011-12-24 07:15:27

标签: iphone objective-c class object nsmutablearray

我有一个类SplitMonths和January,使用类SplitMonths我尝试将对象存储在1月类的NSMutableArray中,但我似乎无法使它工作。

SplitMonths.h

@class January;
@interface ... {
NSMutableArray * calEvents;

January *janClass;      
}
-(void)separate;
@property (nonatomic, assign) January *janClass;

SplitMonths.m

#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]);

}

January.h

@interface January : UITableViewController
{
    NSMutableArray *JanEvents;
}
@property(nonatomic, retain)NSMutableArray *JanEvents;
@end

January.m

@synthesize JanEvents;

添加我检查并且calEvents确实包含包含@“Jan”的对象我已经使用断点测试了它们,它们只是不会添加到nsmutablearray。

0 个答案:

没有答案