Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 07-09-2009, 09: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
 
Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 24,327
Threads: 39,123
Posts: 171,541
Top Poster: smasher (2,577)
Welcome to our newest member, tpearce
Powered by vBadvanced CMPS v3.1.0

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