I think everyone has read the basic tutorial on iPhone 4 and ipad2 development. xcode in this book is different from the latest version. With view base application removed, only single view application is similar.
First, create a single view application. Note that we do not need to reference the Count automatically here.
Click mainstoryboard_iphone.storyboard in the project list to edit the interface:
We create two buttons and a blank text for output:
Directory structure and view structure:
2. Then we write code to connect to the IB Interface Editor: here we can think that iboutlet is the output of interaction with IB, while ibaction is the event of interaction with IB.
Compile viewcontoller. h:
#import <UIKit/UIKit.h>@interface ViewController : UIViewController{}@property (nonatomic,retain) IBOutlet UILabel * statusText;-(IBAction)buttonPressed:(id)sender;@end
Then implement the function in viewcontoller. M:
# Import "viewcontroller. H "@ implementation viewcontroller @ synthesize statustext;-(ibaction) buttonpressed :( ID) sender {nsstring * Title = [Sender titleforstate: uicontrolstatenormal]; // sender is used to obtain the titleforstate text of Different buttons. The function nsstring * newtext = [[nsstring alloc] initwithformat: @ "% @ button pressed is used to obtain the text of Different buttons. ", title]; // put the text in the title into newtext statustext. TEXT = newtext;}-(void) viewdidload {[Super vie Wdidload]; // do any additional setup after loading the view, typically from a nib .} -(void) viewdidunload {[Super viewdidunload]; self. statustext = nil; // release any retained subviews of the main view .} -(bool) shouldautorotatetointerfaceorientation :( uiinterfaceorientation) interfaceorientation {If ([[uidevice currentdevice] userinterfaceidiom] = uiuserinterfaceidiomphone) {return (interfaceorien Tation! = Uiinterfaceorientationportraitupsidedown);} else {return yes;}-(void) dealloc {[statustext release]; [Super dealloc];} @ end
Then we connect the Code with IB:
Select mainstoryboard_iphone.storyboard, right-click buton in View Controller scene, and select touch down and
Bottonpressed:
Connect lable and statustext in the following link:
Finally, run the program and click botton to see the effect: