开发者

NSMutableArray is empty when i call it

When i try to call a NSMutableArray from a diffirent class its empty why?

CLASS A

.h
@interface Dashboard : UIViewController {
    NSMutableArray *tablearrayCREDITS;

}
@property(nonatomic,retain)NSMutableArray *tablearrayCREDITS;

.m
@synthesize tablearrayCREDITS;

And im filling it with data from a JSON array.This all works as it should be..

CLASS B

.h
    #import "Dashboard.h"

    @interface CreditsAndDebits : UIViewController {


    //nothing needed here..

}

.m

@implementation CreditsAndDebits
@synthesize selectedIndexPath;
    NSMutableArray *thearray;

- (void)viewDidLoad {
    Dashboard *db = [[Dashboard alloc]init];
    thearray = db.tablearrayCREDITS;
}

//When i debug it and set a breakpoint on where i allo开发者_JAVA百科cate the Dashboard.. the tablearrayCREDITS says objects 0??, i dont get it? why is it going empty when im calling it?


- (void)viewDidLoad {

    Dashboard *db = [[Dashboard alloc]initWithNibName:@"Dashboard" bundle:nil...........];


    db.tablearrayCREDITS=[[NSMutableArray alloc]init];

    [db.tablearrayCREDITS addObject:@"madhu"];

    thearray = db.tablearrayCREDITS;


//here nslog them
}

//you have to create Dashboard object not mutable array


The array you call is empty because it is probably not initialized yet. You need to initialize that view before you call it. You can do this with the init method for that view.

Or you can initialize that array when the app is launched. You can do this in application didFinishLaunchingWithOptions in the AppDelegate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜