Hey All!
I have declared a variable in the .h file and I want be able to access it from anywhere in the .m files. I am not sure if this is considered a "global" variable or not. In my code, I initialize the variable in the loadView function, and then access it in another function. The call in the second function is giving me errors:
.h file
Code:
@interface SearchParameterViewController : UIViewController <UITextFieldDelegate,UIPickerViewDelegate,UIPickerViewDataSource> {
NSMutableArray *titles;
NSMutableArray *subtitles;
}
.m files
Code:
- (void)loadView {
titles = [NSMutableArray arrayWithObjects:@"Title1", @"Title2", nil];
NSLog(@"Length_a = %d", [titles count]);
}
...
- (NSInteger)pickerView:(UIPickerView*)pickerView numberOfRowsInComponent:(NSInteger)component{
NSLog(@"Length_b = %d", [category_titles count]);
}
The output is:
Length_a = 2
>>> CRASH <<<<
Any ideas why this is happening?