【问题标题】:Polymorphism concept in objective c? [closed]目标c中的多态性概念? [关闭]
【发布时间】:2014-08-25 14:51:06
【问题描述】:

我现在改变了我的问题...

我想知道polymorphism中的objective c喜欢怎么办

Animal = new Dog();

Animal = new Cat();

现在我喜欢这样做

UIViewController *controller = [CheckController alloc]initWithNibName:@"CheckController" bundle:nil];

我想创建一个方法并像这样传递我的xib file 名称和controllerName..

-(void)openNewViewController:(UIViewController *)controllerObject: (NString)*nibName 
{
    // overhere it should do it something like given

     UIViewController *object =[controllerObject alloc]initWithNibName:nibName bundle:nil];

     [self.navigationController pushViewController:object  animated:YES];

}

但不知道该怎么做...

请分享一些代码...

简单来说,我想点击按钮打开一个新视图。我想在其中创建一个函数,在其中传递controllerNameNib file,它将为我打开视图..

在此先感谢...

【问题讨论】:

    标签: ios objective-c xcode uiviewcontroller


    【解决方案1】:

    子类UIButton。 在其中添加属性NSString* nibName。 为您的所有按钮设置此属性。

    在点击处理程序中:

    - (IBAction) onBtn:(MyButton*)sender {
        UIViewController* vc = [[NSClassFromString(sender.nibName) alloc] initWithNibName:sender.nibName bundle:nil];
        [self.navigationController pushViewController:vc animated:YES];// or other code with viewcontroller
        //add [vc release]; if it's not ARC
    }
    

    【讨论】:

    • 我不知道如何继承 UIButton
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-21
    • 1970-01-01
    • 1970-01-01
    • 2014-01-28
    • 2012-10-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多