首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIApplication sharedApplication帮助?

UIApplication sharedApplication帮助?
EN

Stack Overflow用户
提问于 2011-08-16 05:22:14
回答 3查看 2.5K关注 0票数 1

我正在尝试访问一个变量,该变量创建一个导航控制器,该控制器是我在视图控制器的App Delegate中定义的(我正在构建一个标签栏应用程序,每个选项卡都有一个.plist,就像一个下钻应用程序一样)。我正在试着改掉在结构或联合之外的东西中写着"request for member "indNavControl“的错误。有人能帮我吗?

代码:

代码语言:javascript
复制
- (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方法引用我的视图控制器,但是我不知道怎么做。

EN

回答 3

Stack Overflow用户

发布于 2011-08-16 05:31:30

您是否在此处导入了A37dgAppDelegate.h和IndustriesViewController.h?

票数 0
EN

Stack Overflow用户

发布于 2011-08-16 05:31:49

您是否在AppDelegate中将“indNavControl”声明为属性?应该有

代码语言:javascript
复制
@property (nonatomic, retain) NSObject *indNavController;

或者在AppDelegate.h文件中类似的内容。检查一下你有没有。如果没有,请添加它。

EDIT:另外,因为在

代码语言:javascript
复制
[AppDelegate.indNavControl];

你应该去掉这一行中的and。

EDIT2:你的应用委托有多个实例:在'if‘语句的开头和内部。他们的名字是一样的。你应该删除

代码语言:javascript
复制
A37dgAppDelegate *AppDelegate = ...

在"if“语句中,因为名为"AppDelegate”的变量已经存在。

票数 0
EN

Stack Overflow用户

发布于 2011-08-16 08:03:09

哪条线?YOu有一个拼写错误(AppDelegate.indNavControll)。

而且看起来你正在使用可怕的做法(是的,我知道Apple就是这么做的),将实例变量和属性命名为相同的名称,这使得从上下文中读取东西变得更加困难。indNavControl也是另一个类的属性吗?以及该类的实例变量?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7070989

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档