3

首先,我不知道控制器是否是正确的词。我想要达到的就是这个。

   @interface ClubViewController : CoreDataTableViewController :NRGridViewController
   {

我知道这在 Objective-C 中是不可能的。但是有没有办法解决这个问题?因为我想使用 CoreDateTableViewController 和 NRGridViewController。

亲切的问候

史蒂夫 编辑

这就是我的故事板层次结构的样子。

-ViewController
  -TableView
      -View
      -TableViewCell

所以我有一个 tableview 控制器,但在这个 tableview 控制器上方你会发现一个带有三个按钮的小视图。当我按下按钮 1 时,我想拿走 tableview 并使用 NRGridview 控制器绘制一个 gridView。但是当我按下按钮 2 和 3 时,我使用 CoreDataTableViewController 填充了我的表格视图。

我希望这能更多地解释我的问题。

4

3 回答 3

2

我认为一种方法是使用容器视图,其中包含容器视图控制器。该容器控制器将有 2 个子控制器,它们是您的 CoreDateTableViewController 和 NRGridViewController。我已经实现了类似的东西,如果你有兴趣,我可以给你看一些代码。

编辑后:在一个测试应用程序中,我从一个视图模板和一个故事板开始。我在视图的顶部添加了两个按钮,在视图的下半部分添加了一个容器视图(第一个控制器属于 ViewController 类)。然后我拖出一个新的视图控制器,并将控件从容器视图拖到新控制器并选择“嵌入segue”(这会将视图调整为与容器视图相同的大小)。该控制器的类已更改为我的子类 ContainerController。然后,我为将由容器控制器管理的 2 个视图创建了另外 2 个控制器(视图需要在 IB 中将其大小设置为“自由格式”,以便您可以将大小设置为与容器视图相同)。下面是 ContainerController 中的代码:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.cont1 = [[FirstController alloc]initWithNibName:@"FirstView" bundle:nil];
    self.cont2 = [[SecondController alloc]initWithNibName:@"SecondController" bundle:nil];
    [self addChildViewController:self.cont1];
    self.currentController = self.cont1;
    [self.view addSubview:self.cont1.view];
}

-(void)switchToFirst {
    if (self.currentController != self.cont1) {
        [self addChildViewController:self.cont1];
        [self moveToNewController:self.cont1];
    }
}

-(void)switchToSecond {
    if (self.currentController != self.cont2) {
        [self addChildViewController:self.cont2];
        [self moveToNewController:self.cont2];
    }
}

-(void)moveToNewController:(id) newController {
    [self.currentController willMoveToParentViewController:nil];
    [self transitionFromViewController:self.currentController toViewController:newController duration:.6 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{}
                            completion:^(BOOL finished) {
                                [self.currentController removeFromParentViewController];
                                [newController didMoveToParentViewController:self];
                                self.currentController = newController;
                            }];
}

我在 ViewController 中拥有的唯一代码是用于切换视图的 2 个按钮的 IBActions。这些方法只是调用容器控制器中的方法:

-(IBAction)chooseFirstController:(id)sender {
    [self.childViewControllers.lastObject switchToFirst];
}

-(IBAction)chooseSecondController:(id)sender {
    [self.childViewControllers.lastObject switchToSecond];
}
于 2012-10-12T04:19:48.387 回答
0

您在代码中尝试做的是创建一个作为多个其他类的子类的类,这是不可能的。如果您真的想这样做,请查看以下问题:从两个类继承

如果您尝试创建多个实例:CoreDataTableViewController 和 NRGridViewController 只是类,您必须实例化它们才能获得实际对象。您可以使用实例化例如 NRGridViewController

NRGridViewController *controller=[[NRGridViewController alloc] init];   

我希望这能回答你的问题,理解你的问题有点困难。

于 2012-10-11T14:17:56.167 回答
0
  1. 不要使用 tableViewController,而是使用普通的 TableView(从情节提要拖放到视图上的特定位置)。

  2. 当按下按钮 1 时,使表格视图隐藏在按钮操作方法中。并初始化网格视图/或将网格视图隐藏设置为 NO。(所有视图都具有隐藏在 ios 中的属性)

  3. 当您按下第二个和第三个按钮时,将网格视图设置为隐藏并将表视图隐藏设置为 NO。并获取核心数据并将其存储在数组或字典中,或者您可以重新加载表格视图。(最初,在按下按钮 2 和 3 之前,表格视图没有值。所以你可以设置一个 bool 属性,当你按下按钮 2 或 3 时设置 bool 并使用 bool 重新加载你的 tabe 视图)

如果您没有得到我的解释,请回复我。

于 2012-10-18T06:12:23.027 回答