I have an app that reads from an sqlite table and saves the data in an NSMutableArray that is declared in the main ViewController class subclass of UIViewController, this method is called at viewDidLoad. this NSMutable Array is declared as follows:
@property (strong, nonatomic) NSMutableArray *dataForTable;
This data is displayed in a table which is loaded fine at app launch. Now I declare a method just to log the contents of this NSMutableArray
-(void) arrayTest {
NSLog(@" data in test array is%@",dataForTable);}
and the output is also fine when I call it anywhere inside this class like for eg at
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
[self arrayTest]; . . . . . . }
but this data in this NSMutableArray suddenly becomes (null) when I call to log from another class (a subclass of UITableViewCell created to track touchbegan and touchmoved for sliding of cell from left to right)
[[ViewController alloc]arrayTest];
this gives me output
data in test array is(null)
why is that? now if I call -textFieldShouldBeginEditing the output is fine again. why does array empty itself (or maybe i am just thinking it does) and then outputs the content fine again later?
[[ViewController alloc]arrayTest]
. Second, if you doNSLog(@"arrayTest = %@", [[[ViewController alloc] init] arrayTest]);
you will be accessing a NEW instance of ViewController, so anything you did previously in another instance of ViewController will not be seen. – Hot Licks Sep 13 '13 at 16:41