zl程序教程

您现在的位置是:首页 >  工具

当前栏目

QQ登录

QQ 登录
2023-09-27 14:29:23 时间
复制代码
 1 #import UIKit/UIKit.h 

 3 #import "DXWAppDelegate.h"

 5 int main(int argc, char *argv[])

 7 //消息循环,当程序退出的时候才会y有返回值

 8 @autoreleasepool {

 9 //UIApplication是单粒的,是一个应用程序的象征,一个IOS程序对应一个UIApplication

10 //第三个参数用来指定Application类名(或者为子类),默认为nil(UIApplication类名),第四个参数用来指定代理类

11 return UIApplicationMain(argc, argv, nil, NSStringFromClass([DXWAppDelegate class]));

12 //return UIApplicationMain(argc, argv, NSStringFromClass([UIApplication class]), NSStringFromClass([DXWAppDelegate class]));

15 }
复制代码
复制代码
 1 //

 2 // DXWAppDelegate.m

 3 // firstDemo

 4 //

 5 // Created by dingxiaowei on 13-5-20.

 6 // Copyright (c) 2013年 dingxiaowei. All rights reserved.

 7 //

 9 #import "DXWAppDelegate.h"

11 #import "DXWViewController.h"

13 @implementation DXWAppDelegate

15 - (void)dealloc

17 [_window release];

18 [_viewController release];

19 [super dealloc];

21 #pragma mark - 应用程序加载完毕之后调用

22 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

24 NSLog(@"didFinishLaunchingWithOptions--程序加载完毕");

25 //初始化一个窗口

26 self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

29 //自己手动创建一个按钮

30 // CGRect btnFrame=CGRectMake(100, 360, 100, 50);

31 // UIButton *btn=[[UIButton alloc] initWithFrame:btnFrame]; //也可以这样 //UIButton *btn=[UIButton buttonWithType:UIButtonTypeRoundedRect]; btn.frame=btnFrame;

32 // [btn setTitle:@"我是按钮" forState:UIControlStateNormal];

33 // [self.window addSubview:btn];

36 // Override point for customization after application launch.

37 //传入一个xib文件名来初始化一个控制器

38 self.viewController = [[[DXWViewController alloc] initWithNibName:@"DXWViewController" bundle:nil] autorelease];

39 self.window.rootViewController = self.viewController;

40 //上面的代码内部相当于执行了下面这行代码

41 //[self.window addSubview:self.viewController.view];

42 //设置窗口可见 在众多窗口中keyWindow才能充当主窗口 只有主窗口才能跟用户交互

43 [self.window makeKeyAndVisible];

44 //下面这个方法也能显示主界面,但是不能成为主窗口,也就是说不能跟用户打交到

45 //self.window.hidden=NO;

46 return YES;

48 #pragma mark - 程序失去焦点时候调用(指不能跟用户进行交互了)

49 - (void)applicationWillResignActive:(UIApplication *)application

51 NSLog(@"applicationWillResignActive--程序失去焦点了");

52 // 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.

53 // 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.

55 #pragma mark - 当程序进入后台的时候,就调用这个方法 (比如点击home键)

56 - (void)applicationDidEnterBackground:(UIApplication *)application

58 NSLog(@"applicationDidEnterBackground--程序进入后台");

59 // 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. 

60 // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

62 #pragma mark - 当程序进入前台的时候,调用该方法

63 - (void)applicationWillEnterForeground:(UIApplication *)application

65 NSLog(@"applicationWillEnterForeground--程序进入前台");

66 // 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.

68 #pragma mark - 当应用程序获取焦点的时候调用

69 //获取焦点之后才可以跟用户进行交互

70 - (void)applicationDidBecomeActive:(UIApplication *)application

72 NSLog(@"applicationDidBecomeActive--获取焦点");

73 // 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.

75 #pragma mark - 程序在某些情况下被终结是调用

76 - (void)applicationWillTerminate:(UIApplication *)application

78 NSLog(@"applicationWillTerminate--程序被关闭");

79 // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

82 @end
复制代码
复制代码
 1 #import UIKit/UIKit.h 

 3 @interface DXWViewController : UIViewController

 4 //UI元素不需要我们去进行内存管理

 5 @property(nonatomic,assign) IBOutlet UITextField *qq;

 6 @property(nonatomic,assign) IBOutlet UITextField *pwd;

 8 //IBActoin其实就是void,但是它能够让方法名显示在xib的右击列表中

 9 -(IBAction) login;

11 @end
复制代码
复制代码
 1 #pragma mark - 登陆

 2 -(void)login{

 3 NSString *qqText=_qq.text; //这里的下划线也就代表xib中的文本框

 4 NSString *pwdText=_pwd.text;

 5 NSLog(@"QQ=%@,密码=%@",qqText,pwdText);

 6 //暂时理解:叫出键盘的那个视图就是第一响应者[FirstResponder]

 7 //resignFirstResponder代表这个视图不想当第一相应者,那不想当以后键盘就退出

 8 //退出键盘

 9 //[_qq resignFirstResponder];

10 //[_pwd resignFirstResponder];

11 //或者这种方法(条件:如果第一响应者存在于当前调用着的view中,则能退出第一相应者)

12 [self.view endEditing:YES];

15 - (void)viewDidLoad

17 [super viewDidLoad];

18 // Do any additional setup after loading the view, typically from a nib.

21 - (void)didReceiveMemoryWarning

23 [super didReceiveMemoryWarning];

24 // Dispose of any resources that can be recreated.

27 @end
复制代码
QQ登陆功能的实现2 QQ登陆功能的实现2     由于看到园子里有朋友说需要讲解和剖析实现的步骤,前面的QQ登陆实现只有代码,所以这篇补上    1.  分析 1). 当运行QQ.exe后会出现qq登陆界面的窗体
蓬莱仙羽 麦子学院讲师,游戏蛮牛专栏作家,CSDN博客专家,热爱游戏开发,热爱Coding!