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 ...
随机推荐
- github 初始化操作小记
Git作为一种越来越重要的工具,github又如此流行,现在就简单记录一下git的基础操作,希望能帮助大家快速体验入门! 1 查看本地是否存在”公钥”和”私钥” 如果没有,则执行: ssh-keyg ...
- C语言运算符(注意事项)
1.C语言取余注意事项:% a.求余.模运算符(%)时要求两数必须是整型数据. b.取余的结果,是取决于被除数 (不管除数是正数 还是 负数,模的符号与被除数的符号相同). 例:8÷2=4 ...
- LINQ学习笔记——(2)Lambda表达式
最基本的 Lambda 表达式语法: (参数列表)=>{方法体} 说明: 参数列表中的参数类型可以是明确类型或者是推断类型 如果是推断类型,则参数的数据类型将由编译器根据上下文自动推断出 ...
- BZOJ 1010 HNOI2008 玩具装箱 斜率优化
题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=1010 Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的 ...
- ACM训练大纲
1. 算法总结及推荐题目 1.1 C++ STL • STL容器: set, map, vector, priority_queue, queue, stack, deque, bitset• STL ...
- Internet History,Technology and Security
Internet History,Technology and Security(简单记录) First Week High Stakes Research in Computing,and Comm ...
- java对数组的操作
1 拷贝数组 数组全拷贝 数组定位拷贝 2 判断数组是否相等(每个元素都对应相等) 3 数组和集合的相互转化 import java.util.Arrays; import java.util.Lis ...
- 创建带maven的javaWeb项目
1File——Maven——maven-archtypes-webapp GroupId:表示项目组织唯一标识符 ArtifacrId:表示项目唯一标识符 例如项目名称 Version是项目版本 这三 ...
- [转] const int *a与int *const a,const int *const a的区别
http://blog.csdn.net/zhangheng837964767/article/details/33783511 关键问题点:const 属于修饰符 ,关键是看const 修饰的位置在 ...
- To Chromium之浏览器外框UI
先不去管那些webkit,V8 engine, Parser, security,IPC... 先来看看Chromium的外框UI是那些code负责的,如果自己可以定制化一下,应该蛮好玩的. TBD. ...