Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Ralle

macrumors newbie
Original poster
Jan 6, 2009
7
0
So I have been searching in a few hours for why my iPhone app hates me. This is the error I get:
Warning: local declaration of 'searchBox' hides instance variable.
Here is my AppDelegate.m
Code:
#import "RejseAppDelegate.h"

@implementation RejseAppDelegate

@synthesize window;


- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    // Override point for customization after application launch
    [window makeKeyAndVisible];
}

- (void)searchBarSearchButtonClicked:searchBox;
{
	Warning: local declaration of 'searchBox' hides instance variable.
	NSString* sbc = [searchBox text];
	[navBar setTitle:sbc];
	
	NSString* purl = @"a";
	NSString* ppurl = [purl stringByAppendingString:sbc];
	
	NSString* url = [ppurl stringByAppendingString:@"b"];
	
	[ppurl release];
	[purl release];
	
	NSLog(url);
	
	[url release];
	[sbc release];
}

- (void)dealloc {
    [window release];
    [super dealloc];
}


@end

AppDelegate.h
Code:
#import <UIKit/UIKit.h>

@interface RejseAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
	IBOutlet UITableView *resultList;
	IBOutlet UISearchBar *searchBox;
	IBOutlet UINavigationItem *navBar;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

- (void)searchBarSearchButtonClicked:searchBox;

@end

I really don't understand why it says that I am hiding the instance variable.
 

admanimal

macrumors 68040
Apr 22, 2005
3,531
2
It is saying that the searchBox parameter that is part of your searchBarSearchButtonClicked method makes it impossible to access your class' instance variable with the same name in that method. As long as you only have one search box it won't really matter, but you can change the name of either searchBox to get rid of the warning.
 

plinden

macrumors 601
Apr 8, 2004
4,029
142
Is this supposed to be a method declaration?
Code:
[B]- (void)searchBarSearchButtonClicked:searchBox;[/B]
{
	Warning: local declaration of 'searchBox' hides instance variable.
	NSString* sbc = [searchBox text];
	[navBar setTitle:sbc];
	
	...
}
 

Ralle

macrumors newbie
Original poster
Jan 6, 2009
7
0
Well I copied the event from the apple documentation and I am not 100% sure about how everything works.
I would like to access the searchBox's text somehow and I dunno which variable to rename for it to still work.

The event is from a searchBar and I want the function to execute whenever the 'Search' button is clicked.

This is how the app will look:
picture5sf4.png


EDIT:
Okay so I have changed this:
- (void)searchBarSearchButtonClicked:searchBox;
to this:
- (void)searchBarSearchButtonClicked:searchBoxt;
which apparently works.

Thanks!
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
The problem is because you have an class instance variable called searchBox - which is connected to an object on your nib. When you declare the method.
Code:
- (void)searchBarSearchButtonClicked:searchBox;
which is actually incorrect as it should be
Code:
- (void)searchBarSearchButtonClicked:(UISearchBar*)searchBox;
you are creating a completely different variable called searchBox which could be a pointer to something completely different.

Incidently, I very much doubt you copied this off Apple's website as your code is riddled with errors. I strongly advise you look into memory management as you're trying to release a load of stuff that's already autoreleased. Your app will crash.
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
Incidently, I very much doubt you copied this off Apple's website as your code is riddled with errors. I strongly advise you look into memory management as you're trying to release a load of stuff that's already autoreleased. Your app will crash.
I agree. Plus, based on the root of the OP's question, they don't seem to have a basic understanding of method declarations and parameters. I would suggest before going any further that it's time to step back and learn some Objective-C fundamentals.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.