objective c Class code not executing? what is my problem?
Having some issues with code not executing within the classes I created 开发者_如何学Cand thought I initialized and implemented correctly here are all the files. There is a class with an array of another class. Then implemented in the code finally but for some reason none of the NSLog calls seem to execute except the one immediately before [mobdefs createTable] in the main code. All help appreciated...
// Mobdefs.h
@interface Mobdefs : NSObject {
@public NSMutableArray *mobInfo;
}
@property(retain) NSMutableArray *mobInfo;
-(void) createTable;
@end
// Mobdefs.m
#import "Mobdefs.h"
#import "Mobrec.h"
@implementation Mobdefs
@synthesize mobInfo;
- (id) init
{
mobInfo = [[NSMutableArray alloc] init];
return self;
}
-(void) addmobrec
{
MobRec *aNewMobRec = [[MobRec alloc] init];
aNewMobRec.mName=@"newbie";
[mobInfo addObject:aNewMobRec];
[aNewMobRec release];
NSLog(@"MobRec Added\n");
}
-(void) createTable
{
NSLog(@"Populating mob table.\n"); // *** THIS CODE NEVER SEEMS TO GET EXECUTED
}
@end
//main.h
Mobdefs *mobdef;
//main.m
NSLog(@"just before createTable call\n");
[mobdef createTable];
although the createTable code is called in the main the only NSLog output I get is the 'just before createtable...'
It doesn't seem that you have initialized mobdef
. Add the following:
mobdef = [[Mobdefs alloc] init];
to your main.m
before you invoke the method on it.
Objective-C silently ignore calls on nil
, as mobdef
would be initialized to initially.
are you allocating and initializing mobdef in main.m?
精彩评论