2010-10-19 89 views
1

我正在開發一個iphone應用程序,在這個應用程序中我需要有一個控件,可以在所有視圖中說一個按鈕。Iphone開發中的主頁面概念

我想知道在Iphone開發中是否有相當於Asp.net主頁的集中?

回答

1

當然,使用自定義的UIView或UIViewController類和子視圖從你的所有觀點或視圖控制器。

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

我們可以使用以下步驟來實現它。 1.使用'UIView'的子類創建一個新文件並將其命名爲'customButom' 2.添加一個UIView接口文件並將其命名爲customButtom.xib並將customButtom文件與xib鏈接。 3.之後,將UIView大小設置爲Utility in Utility Panel。並設置你想要的寬度和高度。在這個例子中,我已經設置了它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