Iphone开发中的母版页概念

时间:2010-10-19 15:52:03

标签: iphone master

我正在开发一个iphone应用程序,我需要在我的所有视图中都有一个控件,比如一个按钮。

我想知道在Iphone开发中是否有相同的Asp.net母版页集中度?

TA

3 个答案:

答案 0 :(得分:1)

当然,使用自定义UIView或UIViewController类并从中查看所有视图或视图控制器。

答案 1 :(得分:0)

1. Create a viewController class as TopViewController and delete already created view first then add a view from IB (drag drop) and connect to File's Owner (view) then set height and width what you want.
2. Create object of  TopViewController like-
  TopViewController *topVC=[[TopViewController alloc] initWithNibName:@"TopViewController" bundle:nil];
  [self.view addSubView:topVC.view];

答案 2 :(得分:0)

我们可以使用以下步骤实现它。 1.创建一个子类为'UIView'的新文件,并将其命名为'customButom' 2.添加UIView接口文件并将其命名为customButtom.xib,并将customButtom文件与xib链接。 3.此后,在实用程序面板中将UIView大小设置为Freedom。并设置所需的宽度和高度。在这个例子中,我将其设置为160x50 我已经为事件句柄创建了一个协议,属性和IBAction。

 //customButton.h
#import<UIKit/UIKit.h>

// createdcustomButtonDelegate protocol 

@protocolcustomButtonDelegate<NSObject>
    -(void)performButtonClicked;
@end


@interfacecustomButton : UIView

    @property(nonatomic,retain)id<customButtonDelegate>delegate;

    -(IBAction)customButtonClicked:(id)sender;

@end

//customButton.m  Implemented properties and button action `

#import"customButton.h"

@implementationcustomButton
   -(id)initWithFrame:(CGRect)frame {
      self = [superinitWithFrame:frame];
      if (self) {
        UIView *buttonView =[[[NSBundlemainBundle]loadNibNamed:@"customButton"owner:selfoptions:nil] objectAtIndex:0];
    [selfaddSubview:buttonView];
    }
    returnself;
}


-(IBAction)customButtonClicked:(id)sender {
    if (self.delegate != nil) {
       [self.delegateperformButtonClicked];
    }
}

@end


// Viewcontroller.h  Import customButton.h file in our view controller and add delegate      `

#import<UIKit/UIKit.h>

#import"customButton.h"

@interfaceViewController : UIViewController<UIAlertViewDelegate,customButtonDelegate>
@end

// Viewcontroller.m file

@interfaceViewController ()
@end

@implementationViewController {
   customButton *buttonView;
}


- (void)viewDidLoad {
    [superviewDidLoad];
    // we can display / set our custom view on specific location on view. just need to provide your desire Frame

   //creating customButton object and added this object to our view. 
   buttonView = [[customButtonalloc]initWithFrame:CGRectMake(80, 465, 160, 50)];
   buttonView.delegate = self;
   [self.viewaddSubview:buttonView];
}


#pragma mark custombutton delegate
-(void)performButtonClicked {
   NSLog(@"Perform whatever you want to");
}
@end