`
热带翎羽
  • 浏览: 62522 次
  • 性别: 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  
楼主编辑器的配色是怎么弄的 看起来挺舒服的

相关推荐

    iphone开发入门经典源码

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

    《iPhone开发基础教程》

    本书覆盖面广、结构清晰,是一本有关iPhone开发的全新入门指南。它面向具备基本Objective-C知识的iPhone初、高级开发用户,不论你是经验丰富的开发人员,还是初涉编程领域的新手,都可以从本书中得到有用的信息。书...

    微信小程序实例-智能小时钟.zip

    本微信小程序涉及基础的 JavaScript、WXML、CSS 等前端知识,以及常见的微信API和组件使用,适合新手学习入门。 当你遇到问题时,I insist 微信小程序官方文档。 Base timer。页面基于WEUI组件库,微信原生视觉体验...

    Cocoa入门学习.rar

    每周写一篇,贡献给各位fans, 对象是没有编程经验的新手或dummy, 大家共 同上路 ,一起进步! -- MacNuts May 29, 2002 第一个Cocoa 程序 我们的程序将是这样的一个显示文字的简单程序:点左 的按钮会显示按钮上 的...

    新手程序员刷题程序-PlanetWars:星球大战

    程序员刷题程序智能系统2017 这是智能系统课程的实用材料,基于回合制战略游戏星球大战。 入门 要了解游戏的概念,请访问。 挑战的灵感来自这个项目,并且非常相似。 (Android 和 iPhone 都有免费的多人游戏版本,...

    Learn iPhone and iPad cocos2d Game Development

     1.5.2 iphone应用程序开发者将学会什么  1.5.3 cocos2d开发者将学会什么  1.6 章节介绍  1.7 问题和反馈 第2章 入门  2.1 准备工作  2.1.1 系统要求  2.1.2 注册成为ios开发者  2.1.3 证书和授权文件  ...

    新手程序员刷题程序-planet-wars:星球大战

    程序员刷题程序智能系统2017 这是智能系统课程的实用材料,基于回合制战略游戏星球大战。 入门 要了解游戏的概念,请访问。 挑战的灵感来自这个项目,并且非常相似。 (Android 和 iPhone 都有免费的多人游戏版本,...

    新手程序员刷题程序-IS.2017:IS.2017

    程序员刷题程序智能系统2017 这是智能系统课程的实用材料,基于回合制战略游戏星球大战。 入门 要了解游戏的概念,请访问。 挑战的灵感来自这个项目,并且非常相似。 (Android 和 iPhone 都有免费的多人游戏版本,...

    iOS移动开发从入门到精通.epub

    本书由资深iOS开发工程师精心编撰,系统地介绍了使用iOS 10+Swift 3+Xcode 8开发移动...本书适合iOS开发新手、iOS程序员、iPhone开发人员、iPad开发人员使用,也可以作为相关培训机构和大专院校相关专业的教学用书。

    新手程序员刷题程序-intelligent-systems:蒙特卡洛树搜索星球大战游戏

    程序员刷题程序智能系统2017 这是智能系统课程的实用材料,基于回合制战略游戏星球大战。 入门 要了解游戏的概念,请访问。 挑战的灵感来自这个项目,并且非常相似。 (Android 和 iPhone 都有免费的多人游戏版本,...

    新手程序员刷题程序-planet-wars:星球大战代理的基本代码,以及用于玩锦标赛的代码

    程序员刷题程序智能系统2017 这是智能系统课程的实用材料,基于回合制战略游戏星球大战。 入门 要了解游戏的概念,请访问。 挑战的灵感来自这个项目,并且非常相似。 (Android 和 iPhone 都有免费的多人游戏版本,...

    android开发资料大全

    android程序编写及调试新手入门 大家一起学Android(Windows篇) android入门与提高必看指南 Android入门逆引手册 Android开发指南中文版、创意设计 【Android系统原理与开发要点详解】/底层 应用 框架 Android核心...

    JAVA上百实例源码以及开源项目

    此时此景,笔者只专注Android、Iphone等移动平台开发,看着这些源码心中有万分感慨,写此文章纪念那时那景! Java 源码包 Applet钢琴模拟程序java源码 2个目标文件,提供基本的音乐编辑功能。编辑音乐软件的朋友,这...

    JAVA上百实例源码以及开源项目源代码

    此时此景,笔者只专注Android、Iphone等移动平台开发,看着这些源码心中有万分感慨,写此文章纪念那时那景! Java 源码包 Applet钢琴模拟程序java源码 2个目标文件,提供基本的音乐编辑功能。编辑音乐软件的朋友,这...

Global site tag (gtag.js) - Google Analytics