`
热带翎羽
  • 浏览: 63967 次
  • 性别: Icon_minigender_1
  • 来自: 福州
社区版块
存档分类
最新评论

新手iPhone入门程序

阅读更多
思路:
1) Interface Builder制作界面
2) 头文件中增加Outlet和事件响应函数
3) 建立界面与代码的关联
4) 添加实际代码(初始化、按键响应等)

效果:






代码:
//
//  QuizAppDelegate.h
//  Quiz
//
//  Created by bruce.lin on 6/21/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface QuizAppDelegate : NSObject <UIApplicationDelegate> {

    int currentQuestionIndex;
    
    NSMutableArray *questions;
    NSMutableArray *answers;
    
    IBOutlet UILabel *questionField;
    IBOutlet UILabel *answerField;
    
    UIWindow *window;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

-(IBAction) showQuestion:(id)sender;
-(IBAction) showAnswer:(id)sender;

@end

//
//  QuizAppDelegate.m
//  Quiz
//
//  Created by bruce.lin on 6/21/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "QuizAppDelegate.h"

@implementation QuizAppDelegate


@synthesize window=_window;


-(id)init
{
    [super init];
    questions=[[NSMutableArray alloc] init];
    answers=[[NSMutableArray alloc] init];

    [questions addObject:@"iPhone多少米?"];
    [answers addObject:@"为啥告诉你"];
    
    [questions addObject:@"路边野花不要采"];
    [answers addObject:@"一只红杏出墙来"];
    
    currentQuestionIndex=0;
    
    return self;
}


-(IBAction) showQuestion:(id)sender
{
    currentQuestionIndex++;
    
    if(currentQuestionIndex >= [questions count])
    {
        currentQuestionIndex=0;
    }
    
    [questionField setText:[questions objectAtIndex:currentQuestionIndex]];
    
    NSLog(@"Current question is: %@",[questions objectAtIndex:currentQuestionIndex]);
    
    [answerField setText:@"?"];
}

-(IBAction) showAnswer:(id)sender
{
    [answerField setText:[answers objectAtIndex:currentQuestionIndex]];
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
     */
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    /*
     Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
     */
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    /*
     Called when the application is about to terminate.
     Save data if appropriate.
     See also applicationDidEnterBackground:.
     */
}

- (void)dealloc
{
    [_window release];
    [super dealloc];
}

@end

  • 大小: 528.3 KB
  • 大小: 53.3 KB
分享到:
评论
7 楼 抢街饭 2011-06-30  
羡慕 一直想与IPhone 接触 可是一直没有机会
6 楼 热带翎羽 2011-06-28  
enefry 写道
楼主确定新手看的懂?

配书看,肯定没问题
5 楼 enefry 2011-06-28  
楼主确定新手看的懂?
4 楼 热带翎羽 2011-06-24  
我在看:iPhone Programming: The Big Nerd Ranch Guide
3 楼 lsk 2011-06-24  
楼主不错啊,我最近也在研究 ios dev, 有什么好的资源推荐下
2 楼 热带翎羽 2011-06-23  
preference里的主题选择:midnight
1 楼 zhongshan99 2011-06-23  
楼主编辑器的配色是怎么弄的 看起来挺舒服的

相关推荐

    1、Iphone入门

    【Iphone入门】教程主要针对初次接触iPhone应用开发的新手,通过一步步的实践操作,教你如何从零开始创建一个简单的“Hello, World”应用程序。以下是详细的步骤解析: 1. **安装准备**:首先确保你的Mac操作系统...

    iphone开发入门经典源码

    《iPhone开发入门经典》基于... 《iPhone开发入门经典》通过简洁的语言和详细的步骤,帮助读者迅速掌握开发iPhone应用程序所需的基本知识,适合没有任何编程经验的新手阅读,也可供有志于从事iPhone开发的人员参考。

    iPhone开发快速入门简介

    开发iPhone应用对于新手来说可能是一个挑战,但有了合适的入门资料,这个过程会变得容易很多。本文将围绕iPhone开发的基础知识展开,包括硬件特性、软件架构、开发环境、Objective-C编程语言、Cocoa框架、MVC模式,...

    iPhone应用程序编程指南中文高清版

    ### iPhone应用程序编程指南知识点概述 #### 一、iPhone SDK与本地应用程序 - **定义与区别**:iPhone SDK...无论是新手还是经验丰富的开发者,都能从中获得宝贵的启示和技巧,有效提升应用程序的质量与用户体验。

    iphone的一个小程序

    【标题】:“iPhone小程序开发入门教程” 在移动应用开发领域,iPhone应用程序的开发因其广泛的用户基础和优秀的用户体验而备受关注。对于初次接触iOS编程的新手来说,了解如何创建一个简单的iPhone小程序是踏入这...

    Unity基础中文教程 适合新手入门

    根据提供的文件内容,以下是对“Unity基础中文教程 适合新手入门”的知识点梳理: Unity是一款专业的游戏开发工具,其主要特点和功能可以概括为: 1. 简单易用的游戏制作者界面:Unity提供了直观的界面,使得新手...

    iPhone入门学习汇总

    总结,学习 iPhone 开发,尤其是对新手来说,理解如何使用 UITabBarController 和 AddressBook 框架至关重要。掌握这两种技术,可以创建用户友好的多页面应用,并且能与用户的联系人数据进行互动。这仅仅是 iPhone ...

    iPhone4开发入门

    【标题】"iPhone4开发入门"是一本专为初学者设计的苹果开发教程,主要针对的是iOS平台上使用iPhone 4设备的应用程序开发。虽然该教程的部分内容可能已随时间而过时,考虑到iPhone 4在iOS设备历史上的重要地位,其...

    ④-第一个iphone程序iPhone101

    从给定的文件信息来看,我们正在探讨的主题是关于如何创建第一个iPhone应用程序,这与苹果公司的iOS开发环境紧密相关。以下是对标题、描述、标签以及部分内容的深入解析,旨在提炼出其中的关键知识点。 ### 一、...

    iphone 开发入门例子 helloworld

    在iOS开发领域,iPhone应用程序的开发主要依赖于Apple..."项目是iPhone开发的起点,它帮助新手熟悉Swift编程、Xcode使用以及基本的iOS应用结构。随着对这些基础知识的掌握,开发者可以逐步探索更复杂的iOS功能和设计。

    IPHONE开源计算器程序(IOS开发入门级)

    标题 "IPHONE开源计算器程序(IOS开发入门级)" 暗示了这是一个适用于iOS设备的开源计算器应用程序,特别适合初学者了解iOS开发,特别是使用Objective-C编程语言。在这个项目中,开发者可以学习到如何构建一个类似HP...

    iphone的一点入门文章

    "iPhone的一点入门文章"这个标题暗示了我们将探讨的是针对新手的iPhone应用程序开发基础知识。在这个主题下,我们将涵盖iOS平台概述、Swift编程语言、Xcode集成开发环境(IDE)、用户界面设计以及App Store发布流程...

    iPhone手机开发入门教程

    ### iPhone手机开发入门教程知识点详解 #### 一、概述 本教程旨在为初学者提供一套系统性...总之,《iPhone手机开发入门教程》是一本非常实用且全面的指南,无论是对于新手还是有一定经验的开发者都是非常有帮助的。

    iPhone4开发入门 Beginning iPhone 4 +源代码.zip

    总的来说,《iPhone4开发入门 Beginning iPhone 4 Development Exploring the iOS SDK》是一本全面的教程,涵盖了从入门到进阶的各个层面,无论你是零基础的新手还是有一定经验的开发者,都能从中获益。通过学习本书...

    IOS新手入门学习资料

    总的来说,这份"iOS新手入门学习资料"集合提供了全面的学习资源,从基础编程到具体的技术方案,覆盖了iOS开发的各个方面。通过深入学习并实践这些内容,你将逐步掌握iOS开发技能,踏上成为一名合格的iOS开发者之路。...

    ihone入门教程 中文

    总的来说,这个“iPhone入门教程 中文”是一份全面的学习资源,无论是对iPhone的新手还是希望涉足iOS开发的初学者都非常有价值。通过学习,读者不仅可以熟练掌握iPhone的日常使用,还能具备一定的iOS应用开发能力。

    傻瓜书之iPhone应用程序开发

    《傻瓜书之iPhone应用程序开发》是一本针对初学者编写的指南,旨在帮助那些对编程有一定基础但对iOS开发不熟悉的读者快速上手。这本书可能并不适合已经具备一定iOS开发经验的人,因为它的内容可能过于基础。下面我们...

Global site tag (gtag.js) - Google Analytics