iphone应用开发教程(工具为Xcode6以上,使用storyboard)

https://developer.apple.com/library/ios/documentation/iphone/conceptual/iphone101/Articles/05_ConfiguringView.html


重点是学习交互事件,控件如何与代码关联,主要是拖动控件到.h 或.m文件。


.h文件内如如下:

#import <UIKit/UIKit.h>
 
@interface HelloWorldViewController : UIViewController <UITextFieldDelegate>
 
@property (weak, nonatomic) IBOutlet UITextField *textField;
@property (weak, nonatomic) IBOutlet UILabel *label;
@property (nonatomic, copy) NSString *userName;
 
- (IBAction)changeGreeting:(id)sender;
 
@end


.m文件内容如下:

The Implementation File: HelloWorldViewController.m
#import "HelloWorldViewController.h"
 
@implementation HelloWorldViewController
 
@synthesize textField=_textField;
@synthesize label=_label;
@synthesize userName=_userName;
 
 
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
    if (theTextField == self.textField) {
        [theTextField resignFirstResponder];
    }
    return YES;
}
 
- (IBAction)changeGreeting:(id)sender {
    self.userName = self.textField.text;
 
    NSString *nameString = self.userName;
    if ([nameString length] == 0) {
        nameString = @"World";
    }
    NSString *greeting = [[NSString alloc] initWithFormat:@"Hello, %@!", nameString];
    self.label.text = greeting;
}
@end

参考资料:http://blog.csdn.net/chinadeng/article/details/8667263 iPhone 开发之二---xcode 4.6 越狱 免证书 真机调试

http://blog.csdn.net/m_changgong?viewmode=contents iphone开发教程1、2、3

你可能感兴趣的:(iphone应用开发教程(工具为Xcode6以上,使用storyboard))