Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 07-09-2009, 10:49 PM   #1 (permalink)
blueFLoyd8
Registered Member
 
Join Date: Mar 2009
Posts: 96
Default Problems with "global" variable scope

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?
blueFLoyd8 is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 158,728
Threads: 89,186
Posts: 380,518
Top Poster: BrianSlick (7,127)
Welcome to our newest member, Raggou
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:37 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.