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 ...
随机推荐
- This content database has a schema version which is not supported in this farm.
I want to move the website to another server. The new server has reinstall Sharepoint2013 serv ...
- [转]Visual Studio 项目类型 GUID 清单
转自:https://www.codeproject.com/Reference/720512/List-of-Visual-Studio-Project-Type-GUIDs Complete li ...
- javac一次性编译多个包下的.java文件
如题是我想要知道的,然后在网上搜了一下 下面是在某些帖子里看到别人说的只言片语 =========================================================== ...
- 14.0 native webview H5切换
在讲这章之前先说明一个问题,那就是 native webview 都是属于原生的...webview目前用的比较多的是谷歌内核和腾讯X5内核 H5是网页! 还是安卓市场---直接写好脚本进入个人中心 ...
- LLLYYY的数字思维(模拟题)
链接:https://ac.nowcoder.com/acm/contest/318/G LLLYYY很喜欢写暴力模拟贪心思维.某一天在机房,他突然抛给了队友ppq一 个问题.问题如下: 有一个函数f ...
- 关于缺失值(missing value)的处理---机器学习 Imputer
关于缺失值(missing value)的处理 在sklearn的preprocessing包中包含了对数据集中缺失值的处理,主要是应用Imputer类进行处理. 首先需要说明的是,numpy的数组中 ...
- web开发速查表(php,css,html5........)
- User Agent的学习
什么是User-Agent? User-Agent是一个特殊字符串头,被广泛用来标示浏览器客户端的信息,使得服务器能识别客户机使用的操作系统和版本,CPU类型,浏览器及版本,浏览器的渲染引擎,浏览器语 ...
- vue里的this
vue中methods对象里的函数, this指向的都是当前实例或者组件.
- document.querySelector()和document.querySelectorAll()
HTML5向Web API新引入了 document.querySelector()和document.querySelectorAll()两个方法,都可以接收三种类型的参数:id(#),class( ...