UIApplication sharedApplication Help?
I'm trying to access a variable that creates a navigation controller that I defined in my App Delegate in a view controller (I'm building a tab bar application with a .plist for each tab, like a drill-down app). I'm trying to get rid of the error that says "request for member "indNavControl" in something not a structure or union. Could somebody help me out?
Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
A37dgAppDelegate *AppDelegate = (A37dgAppDelegate *)[[UIApplication sharedApplication] delegate];
self.indNavControl = [AppDelegate.indNavControl];
//Get the dictionary of the selected data source.
NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row];
//Get the children of the present item.
NSArray *Children = [dictionary objectForKey:@"Children"];
if([Children count] == 0) {
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];
A37dgAppDelegate *AppDelegate = (A37dgAppDelegate *)[[UIApplication sharedApplication] delegate];
[AppDelegate.indNavControll push indNavControl];
[self.indNavControl pushViewController:dvController animated:YES];
[dvController release];
}
else {
//Prepare to tableview.
IndustriesViewController *indViewControl = [[IndustriesViewController alloc] initWithNibName:@"IndustryView" bundle:[NSBundle mainBundle]];
//Increment the Current View
indViewControl.CurrentLevel += 1;
//Set the title;
indViewControl.CurrentTitle = [dictionary objectForKey:@"Title"];
//Push the new table view on the stack
A37dgAppDelegate *AppDelegate = (A37dgAppDelegate *)[[UIApplication sharedApplication] delegate];
[self.indNavControl pushViewController:indViewControl animated:YES];
indViewControl.tableDataSource = Children;
[indViewControl release];
}
}
Really, all I want to do is reference my view controller using the UIApplication sharedApplication method, but I can't figure out how.
你在这里输入“A37dgAppDelegate.h”和“IndustriesViewController.h”吗?
Did you declare 'indNavControl' in your AppDelegate as property? There should be
@property (nonatomic, retain) NSObject *indNavController;
or something like that in your AppDelegate.h file. Check if you have it. If not, add it.
EDIT: Also, since there is no ObjC method in
[AppDelegate.indNavControl];
you should get rid of [ and ] in this line.
EDIT2: You have multiple instances of your app delegate: at the beginning and inside 'if' statement. And their names are the same. You should delete
A37dgAppDelegate *AppDelegate = ...
inside "if" statement, because variable named "AppDelegate" already exists.
Which line? YOu have a typo (AppDelegate.indNavControll).
And it looks like you're using the horrible practice (yeah, I know Apple does it) of naming instance variables and properties the same, which makes things harder to read out of context. Is indNavControl a property of another class too? And an instance variable of that class too?
链接地址: http://www.djcxy.com/p/52404.html