开发者

Passing NSMutableArray between classes with method

Okay, so i hope im on the right track with this.

So this is my first class's .h file, im just declaring the method here:

-(NSMutableArray *)get; 

Now lets jump into the .m file of that first class, this is the method:

-(NSMutableArray *)get  {  
return testArray;
}

I have a NSMutableArray called testArray, it is filled with 2 NSStrings.

I need to pass that array along to my开发者_运维知识库 next class

Of course in the next class i import first class.

Now i need to get the value of testArray in the second class. here is what im doing (not even sure if im doing it right)

True_FalseViewController *controller = [[True_FalseViewController alloc]init];

NSMutableArray *array = [[NSMutableArray alloc]init];

[controller get]; //here i call the method



NSLog(@"%d", array.count);
NSLog(@"%@", array);

What do i do from here? The method returns a NSMutableArray, but i have no idea to get it into the other array called array.

Thanks for any help you can give, Jacob


Why do not you save return value in array? :

NSMutableArray *array  = [controller get];

And that's all.


    array = [[NSMutableArray alloc] initWithArray:[controller Get]];


Are you initializing (alloc + init) the testArray in your first class .m??


Have you checked if the testArray from the first class has a value before you return it?

Try to check if testArray has some value:

NSLog(@"%@",testArray);

It's possible that your testArray doesn't have any value to return in the first place.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜