Brandon
Brandon

Reputation: 2171

Local Declaration Hides Instance Variable - tableView Not Synthesized

I have read about using underscores to fix compiler warnings that say "Local declaration hides instance variable," but I have not been able to implement a fix. The solutions I have read about say to use an underscore in my .h file, and the @synthesize part of in my .m file. However, I do not synthesize my tableView. Please see my header file below:

.h File

@interface ListViewController : GAITrackedViewController <UISearchDisplayDelegate, 
UISearchBarDelegate, UITableViewDataSource, UITableViewDelegate> {

IBOutlet UITableView *tableView;

}

.m File

//SYNTHESIZE
@synthesize listItems, filteredListItems, savedSearchTerm, savedScopeButtonIndex, 
searchWasActive, mapView, loadingImageView, loadingActivity;



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

 //FIRST WARNING for tableView HERE

if (tableView == self.searchDisplayController.searchResultsTableView){
    return [self.filteredListItems count];
    }
    else{
        return [self.listItems count];
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    //SECOND WARNING for tableView HERE

    [tableView setRowHeight: 60.00];
    return 1;

}

Upvotes: 2

Views: 2625

Answers (4)

Narasimha Nallamsetty
Narasimha Nallamsetty

Reputation: 1263

I do also spent lot of time on this issue. Finally I could solve this problem. The thing is we should take care of outlets which are created by us. If you change outlets names then you must connect them properly after change.In my case after lot of struggle I could finish this issue hope it will help others.... For example if You have an outlet/property named tableView and your delegate method also contains tableView.

So you need to change either of them. Typically you go to change the argument names of delegate and datasource as Change :

IBOutlet UITableView *tableView;

To :

IBOutlet UITableView *tableView1;

For more information visit this link->Local Declaration Hides Instance Variable - tableView Not Synthesized

Upvotes: 0

msk_sureshkumar
msk_sureshkumar

Reputation: 443

Dont use same name : IBOutlet UITableView *tableView; use tableview or table_View

Upvotes: 0

Anoop Vaidya
Anoop Vaidya

Reputation: 46533

You have an outlet/property named tableView and your delegate method also contains tableView.

So you need to change either of them. Typically you go to change the argument names of delegate and datasource as

- (NSInteger)tableView:(UITableView *)aTableView 
 numberOfRowsInSection:(NSInteger)section {

Upvotes: 6

Rushi
Rushi

Reputation: 4500

Change :

IBOutlet UITableView *tableView;

To :

IBOutlet UITableView *tableView1;

Make the same required changes in your .m file also. This warning is coming because in below delegate method:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

There is a reference of UITableView with name tableView and you have given the same name. Scope of this variable is function level where as scope of your variable declare in .h is class level.

Upvotes: 3

Related Questions