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 ...
随机推荐
- c#根据ip获取城市地址
用的API是百度.新浪.淘宝: 1.首先是一个检测获取的值是不是中文的方法,因为有的ip只能识别出来某省,而城市名称则为空返回的json里会出现null或undefined. public stati ...
- Java工程师笔试题整理[校招篇]
Java工程师笔试题整理[校招篇] 隔着两个月即将开始校招了.你是不是也想借着这个机会崭露头角,拿到某些大厂的offer,赢取白富美.走上人生巅峰?当然如果你还没能打下Java基础,一定要先打 ...
- 如何搭建SBT编译Scala开发的Android工程
作者:戚明峰 最近接触了shadowsocks的Android客户端项目源码(https://github.com/shadowsocks/shadowsocks-android),刚好这个项目是使用 ...
- Linux环境搭建系列之sorl服务器的安装部署
http://blog.csdn.net/upxiaofeng/article/details/51425732
- 每天一个Linux命令(12):su命令
su命令用于切换当前用户身份到其他用户身份,变更时须输入所要变更的用户帐号与密码. 语法: su(选项)(参数) 选项: -c<指令>或--command=<指令>:执行完指定 ...
- PHP的array_merge()合并数组
,4];print_r(array_merge($arr1,$arr2));返回结果:Array( [a] => 3 [b] => 2 [0] => 4)1注释:当 ...
- 自动化测试学习之路--java 数组
数组的定义与为数组元素分配空间和赋值是分开进行的,称为动态初始化. 在数组定义的同时就为数组元素分配空间并赋值,称为静态初始化. 一维数组举例: //动态初始化 int[] intArr; intAr ...
- python 网络编程(远程执行命令与粘包)
远程执行命令 先来学习一个新模块 , 一会用到的.. 新模块: subprocess 执行系统命令 r = subprocess.Popen('ls',shell=True,stdout=subpro ...
- PHP Fatal error: Undefined class constant 'MYSQL_ATTR_INIT_COMMAND'
最近用ThinkPHP,给公司布置线上的网站的时候,遇到的一个问题,记录一下. 打开IE浏览器的设置,Internet选项里的高级,将”显示友好的HTTP错误消息“前都勾去掉! 再次刷新,看到的错误是 ...
- Go基础篇【第2篇】: 内置库模块 fmt
fmt官方文档说明:https://studygolang.com/pkgdoc import "fmt" mt包实现了类似C语言printf和scanf的格式化I/O.格式化动作 ...