使用具有多个类的一个Xib [英] Working with One Xib with Multiple Classes

查看:101
本文介绍了使用具有多个类的一个Xib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在这里问了一个问题处理多个Xib或修复折叠并在多个Xib文件上展开按钮
然后我想停止使用多个xib并且只有不同类的主xib但是可能吗?
有人可以指导我这样做吗?

I have already asked a question here Handling Multiple Xib or Fixing collapse and expand button on multiple Xib file then I thought to stop using multiple xib and only main xib with different classes but is it possible ?? Can someone guide me in way which is possible for me to do ?

请帮我解决这个问题

UI按钮使用的代码

- (IBAction)btnPupl:(UIButton *)sender {
CGRect rect;
 sender.selected = !sender.selected;


if(sender.selected ){


[sender setImage:[UIImage imageNamed:@"plus_1.png"]forState:UIControlStateNormal];
    pView.hidden = true;
    eomView.hidden = true ;
    eomLable.hidden = true;

        rect = pupileomMainView.frame;
        rect.size.height = rect.size.height - eomView.frame.size.height ;
        pupileomMainView.frame = rect;



    rect = pSepLine1.frame ;
    rect.origin.y = pupileomMainView.frame.size.height + pupileomMainView.frame.origin.y  ;
    pSepLine1.frame = rect ;

    rect = pSepLine2.frame ;
    rect.origin.y = pSepLine1.frame.origin.y +6 ;
    pSepLine2.frame = rect;

    rect = ExternalMainView.frame;
    rect.origin.y = pSepLine2.frame.origin.y + 1;
    ExternalMainView.frame = rect;

    rect = eSepLine1.frame;
    rect.origin.y = ExternalMainView.frame.origin.y + ExternalMainView.frame.size.height  ;
    eSepLine1.frame = rect;

    rect = eSepLine2.frame;
    rect.origin.y = eSepLine1.frame.origin.y + 5 ;
    eSepLine2.frame = rect ;

    rect = laMainView.frame;
    rect.origin.y = eSepLine2.frame.origin.y + 1;
    laMainView.frame = rect;

    rect = laSepLine1.frame;
    rect.origin.y = laMainView.frame.origin.y +laMainView.frame.size.height  ;
    laSepLine1.frame = rect ;

    rect = laSepLine2.frame ;
    rect.origin.y = laSepLine1.frame.origin.y + 5 ;
    laSepLine2.frame = rect ;

    rect = iopMainView.frame;
    rect.origin.y = laSepLine2.frame.origin.y +1;
    iopMainView.frame = rect;

    rect = iopSepLine1.frame;
    rect.origin.y = iopMainView.frame.origin.y + iopMainView.frame.size.height ;
    iopSepLine1.frame = rect ;

    rect = iopSepLine2.frame;
    rect.origin.y = iopSepLine1.frame.origin.y + 5;
    iopSepLine2.frame = rect;

    rect = sleMainView.frame;
    rect.origin.y = iopSepLine2.frame.origin.y + 1 ;
    sleMainView.frame = rect;

    rect = sleSepLine.frame;
    rect.origin.y = sleMainView.frame.size.height + sleMainView.frame.origin.y ;
    sleSepLine.frame = rect;

    rect = sleSepLine2.frame;
    rect.origin.y = sleSepLine.frame.origin.y +5;
    sleSepLine2.frame = rect;

    rect = fundusMainView.frame;
    rect.origin.y = sleSepLine2.frame.origin.y + 1;
    fundusMainView.frame = rect;

    rect= fundusSepLine1.frame;
    rect.origin.y = fundusMainView.frame.origin.y + fundusMainView.frame.size.height ;
    fundusSepLine1.frame = rect ;

    rect= fundusSepLine2.frame;
    rect.origin.y = fundusSepLine1.frame.origin.y+5 ;
    fundusSepLine2.frame = rect ;

    rect = self.examView.frame;
    rect.size.height = rect.size.height - eomView.frame.size.height;
    self.examView.frame = rect;
}

else {

    pView.hidden = false;
    eomView.hidden = false;
    eomLable.hidden = false;

    [sender setImage:[UIImage imageNamed:@"minus_round_d1.png"]forState:UIControlStateNormal];




    rect = pupileomMainView.frame;
    rect.size.height =  rect.size.height + eomView.frame.size.height  ;
    pupileomMainView.frame = rect;

    rect = pSepLine1.frame ;
    rect.origin.y = pupileomMainView.frame.size.height + pupileomMainView.frame.origin.y +1 ;
    pSepLine1.frame = rect ;

    rect = pSepLine2.frame ;
    rect.origin.y = pSepLine1.frame.origin.y +6 ;
    pSepLine2.frame = rect;

    rect = ExternalMainView.frame;
    rect.origin.y = pSepLine2.frame.origin.y + 1;
    ExternalMainView.frame = rect;

    rect = eSepLine1.frame;


推荐答案

是的,可以使用多态性。这是多个类可以发送相同的消息(并且可能以不同的方式表现)的想法。您可以创建一个类: BaseViewController ,它将在<$中定义 btnPupl:(id)sender C $ C> @interface 。这样,任何继承自 BaseViewController 的视图控制器都将继承 btnPupl:(id)sender

Yes it is possible using polymorphism. This is the idea that multiple classes can be sent the same message, (and potentially behave in different ways). You can create a class like: BaseViewController that would have the definition for btnPupl:(id)sender in the @interface. This way any view controller that inherits from BaseViewController will inherit btnPupl:(id)sender.

另一个选项(我将使用第一个选项)是子类 UIButton 并在该子类中实现您想要的行为。

Another option (I'd go with the first one) is to subclass UIButton and implement the behaviour you want in that subclass.

这篇关于使用具有多个类的一个Xib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆