问题显示/隐藏视图(Obj-C iPhone编程)

时间:2010-04-04 23:59:13

标签: objective-c views

好吧,

所以我有一个像applicationDidFinishLaunching这样的UITableView: [self showForumList]; 所述方法执行此操作:

-(void)showForumList {
    ForumList *fl = [ForumList alloc];
    [fl initWithNibName:@"ForumList" bundle:[NSBundle mainBundle]];
    self.ForumList = fl;
    [window addSubview:[self.ForumList view]];
    [fl release];
}
其中self.ForumList先前在接口中定义为ForumList *ForumList;等。

现在,ForumList(本身显然是UITableViewController的扩展名),我有didSelectRowAtIndexPath: - 在其中我有以下代码:

   Forum *f = [Forum alloc];
    NSArray *forums = [f getForumList];

    NSDictionary *selectedForum = [forums objectAtIndex:[indexPath row]];

    NSString *Url = [selectedForum objectForKey:@"url"];
    NSString *Username = [selectedForum objectForKey:@"username"];
    NSString *Password = [selectedForum objectForKey:@"password"];

    NSLog(@"Identified press on forum %@ (%@/%@)", Url, Username, Password);

    [self.globalDelegate showForumListFromForumUsingUrl:Url username:Username password:Password];
    [self.globalDelegate closeForumList];
    NSLog(@"ForumListFromForum init");

此函数中的两个NSLog调用都会执行并按预期执行。现在,问题就在这里。

self.globalDelegate在我的头文件的接口规范中定义为AppDelegate *globalDelegate;。但是,[self.globalDelegate showForumListFromForumUsingUrl:username:password][self.globalDelegate closeForumList]实际上从未被调用过。他们看起来像这样:

-(void)closeForumList {
    NSLog(@"Hiding forum list");
    [[self.ForumList view] removeFromSuperview];
}

-(void)showForumListFromForumUsingUrl:(NSString *)Url username:(NSString *)Username password:(NSString *)Password {
    NSLog(@"Showing forum list from forum");
    ForumListFromForum *fl = [ForumListFromForum alloc];

    [fl initWithNibName:@"ForumListFromForum" bundle:[NSBundle mainBundle]];
    [fl initFromForumWithUrl:Url username:Username password:Password];

    self.ForumListFromForum = fl;
    [window addSubview:[self.ForumListFromForum view]];
    [fl release];
}

该应用程序响应我的新闻,但这些NSLog调用都没有,大概是因为appDelegate中对方法的调用不起作用。

知道我哪里出错了吗?

1 个答案:

答案 0 :(得分:1)

我没有看到一条线,self.globalDelegate被分配了&初始化。也许,这就是原因。

此外,在这些行中检查(在调试器中):

[self.globalDelegate showForumListFromForumUsingUrl:Url username:Username password:Password];
[self.globalDelegate closeForumList];

self.globalDelegate不是零。正如你应该记得的那样 - 消息被认为是正确的,但没有任何反应。