////main.m//Hello////Created by Lishujun on 14-8-28.//Copyright (c) 2014 Lishujun. All rights reserved.//#import<UIKit/UIKit.h>//View Controller Objects@interfaceHelloworldviewcontroller:uiviewcontroller@property (nonatomic, retain) Iboutlet Uitextfield*TextField;@end@implementationHelloworldviewcontroller-(void) loadview{//Create a View objectUIView *contentview =[[UIView Alloc]initwithframe:[[uiscreen Mainscreen] applicationframe]; Contentview.backgroundcolor=[Uicolor Lightgraycolor]; Self.view=Contentview; //Create a text boxSelf.textfield = [[Uitextfield alloc]initwithframe:cgrectmake ( -, -,97.0,31.0)]; Self.textField.borderStyle=Uitextborderstyleroundedrect; Self.textField.keyboardType=Uikeyboardtypenamephonepad; Self.textField.contentVerticalAlignment=Uicontrolcontentverticalalignmentcenter; [Contentview AddSubview:self.textField]; //Create buttonUIButton *button = [[UIButton alloc]initwithframe:cgrectmake (0.0,0.0,320.0,30.0)]; [Button settitle:nslocalizedstring (@"Hello", nil) forstate:uicontrolstatenormal]; Button.center=Contentview.center; [Contentview Addsubview:button]; //Bind button Event[button addtarget:self action: @selector (buttonclicked:) forcontrolevents:uicontroleventtouchupinside];}-(void) buttonclicked: (UIButton *) button{//Method 1: Get text from the view level in the TextBoxNSLog (@"Button Clicked ..."); Uitextfield*textfield = [Self.view subviews][0]; NSLog (@"Hello,%@.", Textfield.text); //Method 2: Change the TextField from a local variable to a class propertyNSLog (@"Hello,%@.", Self.textField.text); //Popup Information with dialog boxUialertview *av = [[Uialertview alloc] Initwithtitle:@"Hello"Message:self.textField.textDelegate: Nil Cancelbuttontitle:@"OK"Otherbuttontitles:nil]; [AV show];}@end//Delegate Object@interfaceHelloworldappdelegate:nsobject <UIApplicationDelegate>{iboutlet UIWindow*window;} @property (nonatomic, retain) UIWindow*window; @property (nonatomic, retain) Helloworldviewcontroller*Viewcontroller;//window must be declared as a property, declared as a local variable, cannot draw a view, display as a black screen//The official Apple document also declares Viewcontroller as a property.@end@implementationhelloworldappdelegate@synthesizewindow;@synthesizeViewcontroller;-(void) Applicationdidfinishlaunching: (UIApplication *) application{Self.window=[[UIWindow alloc] Initwithframe:[[uiscreen Mainscreen]bounds]]; Self.viewcontroller=[[Helloworldviewcontroller alloc]init]; Self.window.rootViewController=Self.viewcontroller; [Self.window makekeyandvisible];}@end//Program EntryintMainintargcChar*argv[]) {@autoreleasepool {returnUiapplicationmain (argc, argv, Nil,@"helloworldappdelegate"); }}
iOS code implementation: Create button, bind button event, read control value