IOS-入門樣本

來源:互聯網
上載者:User

IOS-入門樣本
程式要求

實現點擊一個按鈕,在對應的文字框內顯示當前日期時間(Xcode6.1版本)

實現主要步驟建立一個IOS的基本工程修改介面,開啟Main.storyboard,使用介面編輯器(IB)拖拽出一個按鈕和文本編輯框 (View)在control裡面建立按鈕事件響應函數,-(IBAction)onClickButton:(id)sender (Control)在control裡面建立文字框的串連變數,使得修改該變數反映在修改文字框上 (Control)在介面編輯器裡(IB)面,按住ctrl,從按鈕出拉出一條直線到上面的View Control上,然後挑選清單中的按鈕事件響應函數即可實現按鈕按下和響應函數之間的串連。(或者點擊按鈕,從右側的工具列Show the connections inspector列表中的Touch Up Inside拉一條直線到視窗上面的View Control,然後選擇事件響應函數即可) (從介面拉直線到View Control)開啟介面編輯器(IB),從View Control拉一條直線到文板框,然後挑選清單中定義的文板框變數即可實現文板框和變數的串連(從View Control拉直線到介面)實現邏輯代碼,包括設定變數,響應函數的編寫
範例程式碼ViewController.h
////  ViewController.h//  1129_HelloWolrd////  Created by God Lin on 14/11/29.//  Copyright (c) 2014年 arbboter. All rights reserved.//#import @interface ViewController : UIViewController{    UITextField*    textTime;}@property (nonatomic, retain) IBOutlet UITextField* textTime;-(IBAction)onClickTimeBtn:(id)sender;@end

ViewController.m
////  ViewController.m//  1129_HelloWolrd////  Created by God Lin on 14/11/29.//  Copyright (c) 2014年 arbboter. All rights reserved.//#import "ViewController.h"@interface ViewController ()@end@implementation ViewController@synthesize textTime;-(IBAction)onClickTimeBtn:(id)sender{    if(textTime)    {        NSDate* date = [NSDate date];        textTime.text = [date description];    }}- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view, typically from a nib.}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}@end

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.