0

IBAction 什么都不做。将“返回”记录到控制台,以便连接正常。当调用 IBAction 时,self.topView 也不执行任何操作

-(IBAction)loadSettingsView:(id)sender;

{

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        [[NSBundle mainBundle] loadNibNamed:@"settingsView_iphone" owner:self options:nil]; 
    } else {
        [[NSBundle mainBundle] loadNibNamed:@"settingsView_ipad" owner:self options:nil];
    }
    [self.view addSubview:topView];
}

-(IBAction)loadMainView:(id)sender;
{
    [topView removeFromSuperview];
    NSLog(@"back");

}
4

2 回答 2

3

我希望我不会在这里做出太多假设,但这应该可以解决您的问题。我假设topView是当前班级的成员:

-(IBAction)loadSettingsView:(id)sender;

{

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        topView = [[[NSBundle mainBundle] loadNibNamed:@"settingsView_iphone" owner:self options:nil] objectAtIndex:0]; 
    } else {
        topView = [[[NSBundle mainBundle] loadNibNamed:@"settingsView_ipad" owner:self options:nil] objectAtIndex:0];
    }
    [self.view addSubview:topView];
}

-(IBAction)loadMainView:(id)sender;
{
    [topView removeFromSuperview];
    NSLog(@"back");

}

基本上,loadNibNamed您使用的方法是返回一个包含 nib 中所有顶级视图的数组。如果你想引用这些视图(这里我假设笔尖中有一个视图),你需要实际分配你的topView变量。目前topView可能为零,所以你的removeFromSuperview电话什么也没做。

于 2012-06-12T19:34:28.347 回答
0

资助一个更容易的解决方案。只需在主视图的 nib 中创建一个新视图并将 IBOutlet 附加到它。像梦一样工作。

-(IBAction)loadSettingsView:(id)sender;
{
        [self.view addSubview:settingsView];
}

-(IBAction)loadMainView:(id)sender;
{
    [settingsView removeFromSuperview];
}
于 2012-06-12T21:02:11.010 回答