01-导航实例-QQ空间Demo示例程序源代码
01-导航实例-QQ空间.zip
62.4 KB// MJLoginViewController.h
- //
- // MJLoginViewController.h
- // 01-导航实例-QQ空间
- //
- // Created by apple on 13-12-10.
- // Copyright (c) 2013年itcast. All rights reserved.
- // 登录界面
- #import<UIKit/UIKit.h>
- @interfaceMJLoginViewController : UIViewController
- //登录
- - (IBAction)login;
- @property(weak,nonatomic)IBOutlet UITextField *qqField;
- @property(weak,nonatomic)IBOutlet UITextField *pwdField;
- @end
// MJLoginViewController.m
- //
- // MJLoginViewController.m
- // 01-导航实例-QQ空间
- //
- // Created by apple on 13-12-10.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import"MJLoginViewController.h"
- #import"MJAboutViewController.h"
- #import"MJHomeViewController.h"
- @interfaceMJLoginViewController ()
- @end
- @implementationMJLoginViewController
- - (void)viewDidLoad
- {
- [superviewDidLoad];
- // 1.标题
- self.title =@"登录界面";
- // 2.右边的“关于”按钮
- self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@“关于" style:UIBarButtonItemStyleBordered target:selfaction:@selector(jump2about)];
- // 3.设置返回按钮的文字
- self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回"style:UIBarButtonItemStyleBordered target:nilaction:nil];
- }
- #pragma mark跳到“关于”页面
- - (void)jump2about
- {
- // 1.创建
- MJAboutViewController *about = [[MJAboutViewController alloc] init];
- // about.title = @"关于------";
- // 2.压入栈
- [self.navigationController pushViewController:about animated:YES];
- }
- #pragma mark弹框
- - (void)alert:(NSString *)msg
- {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"友情提示"message:msg delegate:nilcancelButtonTitle:@"好的"otherButtonTitles:nil,nil];
- [alert show];
- }
- #pragma mark登录
- - (IBAction)login {
- // 1.判断有无QQ和密码
- if(_qqField.text.length ==0) {//没有QQ
- [self alert:_qqField.placeholder];
- return;
- }
- if(_pwdField.text.length ==0) {//没有密码
- [self alert:_pwdField.placeholder];
- return;
- }
- // 2.能执行到这里,说明同时输入了QQ和密码。应该跳到下一个界面---首页界面
- MJHomeViewController *home = [[MJHomeViewController alloc] init];
- [self.navigationController pushViewController:home animated:YES];
- }
- @end
// MJAboutViewController.h
- //
- // MJAboutViewController.h
- // 01-导航实例-QQ空间
- //
- // Created by apple on 13-12-10.
- // Copyright (c) 2013年itcast. All rights reserved.
- // 关于界面
- #import<UIKit/UIKit.h>
- @interfaceMJAboutViewController : UIViewController
- @property(weak,nonatomic)IBOutletUIWebView *webView;
- @end
// MJAboutViewController.m
- //
- // MJAboutViewController.m
- // 01-导航实例-QQ空间
- //
- // Created by apple on 13-12-10.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import"MJAboutViewController.h"
- @interface MJAboutViewController ()
- @end
- @implementation MJAboutViewController
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // 1.标题
- self.title =@"关于";
- // 2.加载网页
- // 2.1.获得about.html文件的URL
- NSURL *url = [[NSBundle mainBundle] URLForResource:@"about.html"withExtension:nil];
- // 2.2.封装一个请求对象
- NSURLRequest *request = [NSURLRequest requestWithURL:url];
- // 2.3.加载请求
- [_webView loadRequest:request];
- }
- @end
// MJEditViewController.h
- //
- // MJEditViewController.h
- // 01-导航实例-QQ空间
- //
- // Created by apple on 13-12-10.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import<UIKit/UIKit.h>
- //@class MJHomeViewController;
- @class MJEditViewController, MJPerson;
- @protocol MJEditViewControllerDelegate <NSObject>
- @optional
- //- (void)editViewController:(MJEditViewController *)edit didSaveWithName:(NSString *)name intro:(NSString *)intro;
- - (void)editViewController:(MJEditViewController *)edit didSaveWithPerson:(MJPerson *)person;
- @end
- @interface MJEditViewController : UIViewController
- @property(weak,nonatomic)IBOutlet UITextField *nameField;
- @property(weak,nonatomic)IBOutlet UITextView *introView;
- @property(nonatomic,weak)id<MJEditViewControllerDelegate> delegate;
- @property(nonatomic,strong) MJPerson *person;
- //@property (nonatomic, strong) MJHomeViewController *home;
- @end
// MJEditViewController.m
- //
- // MJEditViewController.m
- // 01-导航实例-QQ空间
- //
- // Created by apple on 13-12-10.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import"MJEditViewController.h"
- #import"MJPerson.h"
- //#import "MJHomeViewController.h"
- @interfaceMJEditViewController ()
- @end
- @implementationMJEditViewController
- - (void)viewDidLoad
- {
- [superviewDidLoad];
- // 1,标题
- self.title =@"编辑个人信息";
- // 2.右上角的保存按钮
- self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"保存"style:UIBarButtonItemStyleDone target:selfaction:@selector(save)];
- // 3.取出模型数据,赋值到对应的子控件上面
- _nameField.text = _person.name;
- _introView.text = _person.intro;
- }
- //重写set方法在这里无效,因为内部的子控件还没有被创建
- //- (void)setPerson:(MJPerson *)person
- //
- //{
- // _person = person;
- //
- // _nameField.text = person.name;
- //
- // _introView.text = person.intro;
- //}
- #pragma mark保存
- - (void)save
- {
- // NSLog(@"%@ - %@", _nameField.text, _introView.text);
- // _home.nameLabel.text = _nameField.text;
- // _home.introView.text = _introView.text;
- //
- //
- // [self.navigationController popViewControllerAnimated:YES];
- if([_delegate respondsToSelector:@selector(editViewController:didSaveWithPerson:)]) {
- //封装模型
- MJPerson *p = [MJPerson personWithName:_nameField.text intro:_introView.text];
- //传递模型数据给代理
- [_delegate editViewController:selfdidSaveWithPerson:p];
- [self.navigationController popViewControllerAnimated:YES];
- }
- }
- @end
// MJHomeViewController.h
- //
- // MJHomeViewController.h
- // 01-导航实例-QQ空间
- //
- // Created by apple on 13-12-10.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import<UIKit/UIKit.h>
- @interfaceMJHomeViewController : UIViewController
- @property(weak,nonatomic)IBOutletUILabel *nameLabel;
- @property(weak,nonatomic)IBOutletUITextView *introView;
- - (IBAction)sendStatus;
- @property(weak,nonatomic)IBOutletUITableView *tableVIew;
- @end
// MJHomeViewController.m
- //
- // MJHomeViewController.m
- // 01-导航实例-QQ空间
- //
- // Created by apple on 13-12-10.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import"MJHomeViewController.h"
- #import"MJPerson.h"
- #import"MJStatus.h"
- #import"MJStatusViewController.h"
- #import"MJEditViewController.h"
- @interface MJHomeViewController () <UIActionSheetDelegate, MJEditViewControllerDelegate, MJStatusViewControllerDelegate, UITableViewDataSource>
- {
- NSMutableArray *_statuses;//所有的说说
- }
- @end
- @implementation MJHomeViewController
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // 1.标题
- self.title =@"个人主页";
- // 2.右上角的编辑按钮
- self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:selfaction:@selector(jump2edit)];
- // 3.设置左上角的注销按钮
- self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"注销"style:UIBarButtonItemStyleBordered target:self action:@selector(logout)];
- _statuses = [NSMutableArray array];
- }
- #pragma mark注销
- - (void)logout
- {
- /*
- cancelButtonTitle:黑色
- destructiveButtonTitle :红色
- otherButtonTitles :白色
- */
- UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"是否要注销”delegate:self cancelButtonTitle:@"否"destructiveButtonTitle:@"是"otherButtonTitles:nil,nil];
- [sheet showInView:self.view];
- }
- #pragma mark - UIActionSheet的代理方法
- #pragma mark监听UIActionSheet的按钮点击
- - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
- {
- if(buttonIndex ==1) return;
- //点击“是”
- //栈顶控制器出栈
- [self.navigationController popViewControllerAnimated:YES];
- }
- #pragma mark跳到编辑页面
- - (void)jump2edit
- {
- MJEditViewController *edit = [[MJEditViewController alloc] init];
- edit.delegate =self;
- edit.person = [MJPerson personWithName:_nameLabel.text intro:_introView.text];
- // edit.view.backgroundColor = [UIColor blueColor];
- // edit.nameField.text = _nameLabel.text;
- // edit.introView.text = _introView.text;
- [self.navigationController pushViewController:edit animated:YES];
- }
- #pragma mark - MJEditViewController代理方法
- - (void)editViewController:(MJEditViewController *)edit didSaveWithPerson:(MJPerson *)person
- {
- // 1.显示名称
- _nameLabel.text = person.name;
- // 2.显示简介
- _introView.text = person.intro;
- }
- - (IBAction)sendStatus {
- //跳到写说说界面
- MJStatusViewController *status = [[MJStatusViewController alloc] init];
- status.delegate =self;
- [self.navigationController pushViewController:status animated:YES];
- }
- #pragma mark - MJStatusViewController代理方法
- - (void)statusViewController:(MJStatusViewController *)statusController didSendStatus:(MJStatus *)status
- {
- // NSLog(@"首页拿到了---%@", status.text);
- // 1.将新的说说对象插入数组的最前面
- [_statuses insertObject:status atIndex:0];
- // 2.刷新表格
- [_tableVIew reloadData];
- }
- #pragma mark -数据源方法
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return_statuses.count;
- }
- #pragma mark每一行显示怎样的cell(内容)
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- // 1.定义一个标识
- staticNSString *ID =@"cell";
- // 2.去缓存池中取出可循环利用的cell
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
- // 3.如果缓存中没有可循环利用的cell
- if(cell ==nil) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
- }
- //取出模型
- MJStatus *s = _statuses[indexPath.row];
- cell.textLabel.text = s.text;
- NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
- fmt.dateFormat =@"yyyy-MM-dd HH:mm:ss";
- cell.detailTextLabel.text = [fmt stringFromDate:s.time];
- returncell;
- }
- @end
// MJPerson.h
- //
- // MJPerson.h
- // 01-导航实例-QQ空间
- //
- // Created by apple on 13-12-10.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import<Foundation/Foundation.h>
- @interfaceMJPerson : NSObject
- @property(nonatomic,copy) NSString *name;
- @property(nonatomic,copy) NSString *intro;
- + (id)personWithName:(NSString *)name intro:(NSString *)intro;
- @end
// MJPerson.m
- //
- // MJPerson.m
- // 01-导航实例-QQ空间
- //
- // Created by apple on 13-12-10.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import"MJPerson.h"
- @implementation MJPerson
- + (id)personWithName:(NSString *)name intro:(NSString *)intro
- {
- MJPerson *p = [[self alloc] init];
- p.name = name;
- p.intro = intro;
- return p;
- }
- @end
// MJStatus.h
- //
- // MJStatus.h
- // 01-导航实例-QQ空间
- //
- // Created by apple on 13-12-10.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import<Foundation/Foundation.h>
- @interfaceMJStatus : NSObject
- @property(nonatomic,copy) NSString *text;
- @property(nonatomic,strong) NSDate *time;
- + (id)statusWithText:(NSString *)text;
- @end
// MJStatus.m
- //
- // MJStatus.m
- // 01-导航实例-QQ空间
- //
- // Created by apple on 13-12-10.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import"MJStatus.h"
- @implementationMJStatus
- + (id)statusWithText:(NSString *)text
- {
- MJStatus *s = [[selfalloc] init];
- s.text = text;
- s.time = [NSDate date];
- returns;
- }
- @end
MJStatusViewController.h
- @classMJStatusViewController, MJStatus;
- @protocolMJStatusViewControllerDelegate <NSObject>
- @optional
- - (void)statusViewController:(MJStatusViewController *)statusController didSendStatus:(MJStatus *)status;
- @end
- @interfaceMJStatusViewController : UIViewController
- @property(nonatomic,weak)IBOutletUITextView *statusView;
- @property(nonatomic,weak)id<MJStatusViewControllerDelegate> delegate;
- @end
// MJStatusViewController.m
- //
- // MJStatusViewController.m
- // 01-导航实例-QQ空间
- //
- // Created by apple on 13-12-10.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import"MJStatusViewController.h"
- #import"MJStatus.h"
- @interfaceMJStatusViewController ()
- @end
- @implementationMJStatusViewController
- - (void)viewDidLoad
- {
- [superviewDidLoad];
- // 1.标题
- self.title =@"写说说";
- // 2.右上角的发布
- self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"发布"style:UIBarButtonItemStyleDone target:selfaction:@selector(send)];
- }
- #pragma mark -发布
- - (void)send
- {
- if([_delegate respondsToSelector:@selector(statusViewController:didSendStatus:)]) {
- //给代理传递说说模型数据
- MJStatus *s = [MJStatus statusWithText:_statusView.text];
- [_delegate statusViewController:selfdidSendStatus:s];
- //出栈
- [self.navigationController popViewControllerAnimated:YES];
- }
- }
- @end
// MJAppDelegate.h
- //
- // MJAppDelegate.h
- // 01-导航实例-QQ空间
- //
- // Created by apple on 13-12-10.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import<UIKit/UIKit.h>
- @interfaceMJAppDelegate :UIResponder<UIApplicationDelegate]] >
- @property(strong,nonatomic)UIWindow*window;
- @end
// MJAppDelegate.m
- //
- // MJAppDelegate.m
- // 01-导航实例-QQ空间
- //
- // Created by apple on 13-12-10.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import"MJAppDelegate.h"
- #import"MJLoginViewController.h"
- @implementation MJAppDelegate
- - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
- {
- self.window= [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
- MJLoginViewController*login = [[MJLoginViewController alloc]init];
- //显示导航控制器
- self.window.rootViewController= [[UINavigationController alloc] initWithRootViewController:login];
- [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:.
- }
- @end
01-导航实例-QQ空间Demo示例程序源代码的更多相关文章
- 03.WebView演练-iOS开发Demo(示例程序)源代码
技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博http://weibo.com/luohanchenyilong //转载请注明出处--本文永久链接:h ...
- iOS多线程
iOS开发Demo(示例程序)源代码
本系列所有开发文档翻译链接地址:iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址(2013年12月29日更新版) iOS程序源代码下载链接:01.大任务.zip22 ...
- 代理设计模式iOS开发Demo(示例程序)源代码
iOS程序源代码下载链接:03-代理设计模式.zip28.3 KB // main.m // // main.m // 03-代理设计模式 // // Created by apple ...
- 1210笔记//关于导航实例-QQ空间//导航实例-storyboard实现//控制器的生命周期//控制器的生命周期方法
一.利用storyboard完成导航1.storyboard中用来跳转的每一根线 都是 一个 UIStoryboardSegue对象1> 自动跳转 (从 某个按钮 拖线到 下一个目的控制器) ...
- 01-QQ 3-最终重构版
Demo示例程序源代码
源代码下载链接:01-QQ 3.zip292.5 KB // QQAppDelegate.h Map // // QQAppDelegate.h // 01-QQ // // Created ...
- 01-modal
Demo示例程序源代码
源代码下载链接:01-modal.zip37.8 KB // MJAppDelegate.h // // MJAppDelegate.h // 01-modal // // Created by ...
- 02-更改窗口的根控制器
Demo示例程序源代码
源代码下载链接:02-更改窗口的根控制器.zip18.0 KB // MJAppDelegate.h // // MJAppDelegate.h // 02-更改窗口的根控制器 // // ...
- 归档普通对象Demo示例程序源代码
源代码下载链接:06-归档普通对象.zip34.2 KB // MJPerson.h // // MJPerson.h // 06-归档普通对象 // // Created by apple o ...
- Python案例之QQ空间自动登录程序实现
不多说,直接上干货! 工具选择: 电脑系统:win7,32 位,下面第二部安装SetupTools时注意系统版本要求: Python: 2.7.11, 相信只要是2.7的就可以实现: Seleniu ...
随机推荐
- CWindowWnd类源码分析
CWindowWnd代码在UIBase.h和UIBase.cpp文件里.主要实现的是一个基本窗口的创建与消息处理. 相关代码: 头文件: class UILIB_API CWindowWnd { pu ...
- JMeter接口响应数据出现乱码的三种解决方法
第一种方法: Content encoding设置为utf-8,若仍为乱码,请用方法2 图1 第二种方法: 修改bin文件夹下的jmeter.properties文件 搜索ISO,把“#sampler ...
- (Python爬虫01)-本想给随笔加个序号才发现这么不方便
本想给随机加个序号,才发现还得去返回看看文章的序号.好在cnblog能断点自动保存. 作为一个小程序员,点赞的同时还在想,谁知道咋实现这种实时保存呢?有知道的给个参考文档呗.太感激了! 重点在这里 有 ...
- 剑指offer-链表中倒数第K个结点14
题目描述 输入一个链表,输出该链表中倒数第k个结点. class Solution: def FindKthToTail(self, head, k): # write code here res=[ ...
- 问题 A: 分数矩阵
题目描述 我们定义如下矩阵:1/1 1/2 1/31/2 1/1 1/21/3 1/2 1/1矩阵对角线上的元素始终是1/1,对角线两边分数的分母逐个递增.请求出这个矩阵的总和. 输入 输入包含多组测 ...
- Nginx 配置 HTTPS自签名证书
工具: OpenSSL ssl的开源实现,几乎实现了市面上所有的加密 libcrypto: 通用加密库, 任何软件要实现加密功能 链接调用这个库 libssl: TLS/SSL 加密库 openssl ...
- Visual Studio 2012安装包
点击下载
- 团队作业4——第一次项目冲刺(Alpha版本)-第三篇
项目冲刺——第三阶段 前两阶段很ok,目测这三天可以搞定! 分工讨论 大体上搞定,设置困难度的功能还未完成. 团队成员 任务 郭达 整合各种代码 刘德培 数据库完善和其他人对接 石浩洋 完善PH ...
- 3GPP规范命名规则解读
http://blog.sina.com.cn/s/blog_6b10255301012co6.html 学习了解电信技术知识的一个很好的手段是阅读3GPP的规范.但是3GPP有大量的规范,我们可能经 ...
- [Elasticsearch] 多字段搜索 (六) - 自定义_all字段,跨域查询及精确值字段
自定义_all字段 在元数据:_all字段中,我们解释了特殊的_all字段会将其它所有字段中的值作为一个大字符串进行索引.尽管将所有字段的值作为一个字段进行索引并不是非常灵活.如果有一个自定义的_al ...