我正在尝试访问一个变量,该变量创建一个导航控制器,该控制器是我在视图控制器的App Delegate中定义的(我正在构建一个标签栏应用程序,每个选项卡都有一个.plist,就像一个下钻应用程序一样)。我正在试着改掉在结构或联合之外的东西中写着"request for member "indNavControl“的错误。有人能帮我吗?
代码:
- (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];
}}
实际上,我想做的就是使用UIApplication sharedApplication方法引用我的视图控制器,但是我不知道怎么做。
发布于 2011-08-16 05:31:30
您是否在此处导入了A37dgAppDelegate.h和IndustriesViewController.h?
发布于 2011-08-16 05:31:49
您是否在AppDelegate中将“indNavControl”声明为属性?应该有
@property (nonatomic, retain) NSObject *indNavController;或者在AppDelegate.h文件中类似的内容。检查一下你有没有。如果没有,请添加它。
EDIT:另外,因为在
[AppDelegate.indNavControl];你应该去掉这一行中的and。
EDIT2:你的应用委托有多个实例:在'if‘语句的开头和内部。他们的名字是一样的。你应该删除
A37dgAppDelegate *AppDelegate = ...在"if“语句中,因为名为"AppDelegate”的变量已经存在。
发布于 2011-08-16 08:03:09
哪条线?YOu有一个拼写错误(AppDelegate.indNavControll)。
而且看起来你正在使用可怕的做法(是的,我知道Apple就是这么做的),将实例变量和属性命名为相同的名称,这使得从上下文中读取东西变得更加困难。indNavControl也是另一个类的属性吗?以及该类的实例变量?
https://stackoverflow.com/questions/7070989
复制相似问题