Master page concept in Iphone development

会有一股神秘感。 提交于 2020-01-05 05:54:09

问题


I am developing an iphone application in which I need to have a control, lets say a button , in all of my views.

I was wondering if there is an equivalent concent for Asp.net master pages in Iphone development?

Ta


回答1:


Sure, use a custom UIView or UIViewController class and subview all your views or view controllers from that.




回答2:


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];



回答3:


We can achieve it using following step. 1. Create a new file with Subclass of ‘UIView’ and name it ‘customButom’ 2. Add a UIView Interface file and name it customButtom.xib and link customButtom file with xib. 3. After this set the UIView size to Freedom in Utility Panel. And set your desired width and height. In this example, I have set it 160x50 I’ve created a protocol, properties and IBAction for the event handle.

 //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


来源:https://stackoverflow.com/questions/3970203/master-page-concept-in-iphone-development

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!