IOS Study Notes (2) Implement basic interaction under xcode 4.3.2

Source: Internet
Author: User

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.