您的位置:首页 > 其它

动漫小屋

2015-12-22 00:00 302 查看
摘要: 项目

//login

//
// LoginViewController.m
// 动漫小屋
//
// Created by dc0061 on 15/12/15.
// Copyright © 2015年 dc0061. All rights reserved.
//

#import "LoginViewController.h"
#import "SaveViewController.h"
#import "User.h"
#import "UserCoreDate.h"
#import "DetailedViewController.h"
#import "MoreViewController.h"

@interface LoginViewController ()<UITableViewDataSource,UITableViewDelegate>
{
UIImageView *_image;
UILabel *_nameLabel;
UILabel *_passLabel;
UILabel *_tishi;

UITextField *_nameField;
UITextField *_passField;

UIButton *_login;
UIButton *_save;
UIButton *_zhuxiao;

UIView *_view;

UITableView *_tableView;
NSArray *_array;

NSUserDefaults *user;
}
@end

@implementation LoginViewController

- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"登陆";

[self layout];
user=[NSUserDefaults standardUserDefaults];
if ([user objectForKey:@"userName"]!=nil) {
[self loginView];
}
}

- (void) layout{
_image = [[UIImageView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
_image.image=[UIImage imageNamed:@"48754"];
[self.view addSubview:_image];

_nameLabel=[[UILabel alloc]initWithFrame:CGRectMake(60, 100, 40, 40)];
_nameLabel.text=@"账号";
[self.view addSubview:_nameLabel];

_passLabel=[[UILabel alloc]initWithFrame:CGRectMake(60, 160, 40, 40)];
_passLabel.text=@"密码";
[self.view addSubview:_passLabel];

_nameField=[[UITextField alloc]initWithFrame:CGRectMake(120, 100, 200, 40)];
_nameField.placeholder=@"请输入账号";
_nameField.textAlignment=NSTextAlignmentCenter;
[_nameField setBorderStyle:UITextBorderStyleRoundedRect];
[self.view addSubview:_nameField];

_passField=[[UITextField alloc]initWithFrame:CGRectMake(120, 160, 200, 40)];
_passField.textAlignment=NSTextAlignmentCenter;
_passField.placeholder=@"请输入密码";
_passField.secureTextEntry=YES;
[_passField setBorderStyle:UITextBorderStyleRoundedRect];
[self.view addSubview:_passField];

_tishi=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2-100, 210, 200, 40)];
_tishi.textColor=[UIColor redColor];
_tishi.textAlignment=NSTextAlignmentCenter;
[self.view addSubview:_tishi];

_login=[[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2-80, 240, 55, 40)];
[_login setTitle:@"登陆" forState:UIControlStateNormal];
[_login setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[_login addTarget:self action:@selector(userLogin) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_login];

_save=[[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2+40, 240, 55, 40)];
[_save setTitle:@"注册" forState:UIControlStateNormal];
[_save setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[_save addTarget:self action:@selector(userSave) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_save];

_array=@[@"我的关注",@"历史记录",@"我的参与",@"参与日报"];
_tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 280, 375, 338)];
_tableView.dataSource=self;
_tableView.delegate=self;
_tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];//隐藏多余的cell
[self.view addSubview:_tableView];
}
- (void) userLogin{
NSString *name=[_nameField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];//去掉首尾的空格
NSString *pass=[_passField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

UserCoreDate *u=[[UserCoreDate alloc]init];
NSArray *array=[u selectUser:name];
if ([array count]==0) {
_tishi.text=@"没有此账号,请注册";
return;
}
if (![pass isEqualToString:[array[0] userPass]]) {
_tishi.text=@"密码输入错误";
return;
}
_tishi.text=@"";
UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"登陆提示" message:@"登录成功" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
user=[NSUserDefaults standardUserDefaults];
[user setValue:name forKey:@"userName"];
[self loginView];
}]];
[self presentViewController:alert animated:YES completion:nil];
}
#pragma mark 登陆成功后加载的
- (void) loginView{
self.navigationItem.title=@"我的空间";
_view=[[UIView alloc]initWithFrame:CGRectMake(0, 64, 375, 216)];
_view.backgroundColor=[UIColor redColor];
[self.view addSubview:_view];
_image = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 375, 216)];
_image.image=[UIImage imageNamed:@"665"];
_image.contentMode = UIViewContentModeScaleAspectFill;
[_view addSubview:_image];

_zhuxiao=[[UIButton alloc]initWithFrame:CGRectMake(300, 10, 60,40)];
[_zhuxiao setTitle:@"注销" forState:UIControlStateNormal];
[_zhuxiao setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[_zhuxiao addTarget:self action:@selector(zhuxiao) forControlEvents:UIControlEventTouchUpInside];
[_view addSubview:_zhuxiao];

UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(50, 100, 275, 40)];
label.text=[NSString stringWithFormat:@"欢迎%@登陆",[user objectForKey:@"userName"]];
label.textAlignment=NSTextAlignmentCenter;
[_view addSubview:label];
}
#pragma mark 注销
- (void) zhuxiao{
[_view removeFromSuperview];
_passField.text=@"";//注销后清空密码
[user removeObjectForKey:@"userName"];
}
#pragma mark 注册
- (void) userSave{
SaveViewController *userSave=[[SaveViewController alloc]init];
[self presentViewController:userSave animated:YES completion:nil];
}

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 1;
}

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
return [_array count];
}

- (NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
return @" ";
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell==nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
}
cell.textLabel.text=_array[indexPath.section];
return cell;
}

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if ([user objectForKey:@"userName"]==nil) {
UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"提示" message:@"请先登陆" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleCancel handler:nil]];
[self presentViewController:alert animated:NO completion:nil];
return;
}
[user removeObjectForKey:@"daily_button_tag"];
[user removeObjectForKey:@"bool"];
DetailedViewController *detailed;
MoreViewController *more;
switch (indexPath.section) {
case 0:

break;
case 1:

break;
case 2:
more=[[MoreViewController alloc]init];
[self.navigationController pushViewController:more animated:YES];
break;
case 3:
detailed=[[DetailedViewController alloc]init];
[self presentViewController:detailed animated:YES completion:nil];
break;
default:
break;
}
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];

}

@end

//save

//
// SaveViewController.m
// 动漫小屋
//
// Created by dc0061 on 15/12/16.
// Copyright © 2015年 dc0061. All rights reserved.
//

#import "SaveViewController.h"
#import "UserCoreDate.h"

@interface SaveViewController ()
{
UIImageView *_image;
UILabel *_nameLabel;
UILabel *_passLabel;
UITextField *_nameField;
UITextField *_passField;
UIButton *_save;
UIButton *_quxiao;
}
@end

@implementation SaveViewController

- (void)viewDidLoad {
[super viewDidLoad];
_image = [[UIImageView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
_image.image=[UIImage imageNamed:@"48754"];
[self.view addSubview:_image];

_nameLabel=[[UILabel alloc]initWithFrame:CGRectMake(60, 100, 40, 40)];
_nameLabel.text=@"账号";
[self.view addSubview:_nameLabel];

_passLabel=[[UILabel alloc]initWithFrame:CGRectMake(60, 160, 40, 40)];
_passLabel.text=@"密码";
[self.view addSubview:_passLabel];

_nameField=[[UITextField alloc]initWithFrame:CGRectMake(120, 100, 200, 40)];
_nameField.placeholder=@"请输入账号6-12位";
_nameField.textAlignment=NSTextAlignmentCenter;
[_nameField setBorderStyle:UITextBorderStyleRoundedRect];
[self.view addSubview:_nameField];

_passField=[[UITextField alloc]initWithFrame:CGRectMake(120, 160, 200, 40)];
_passField.textAlignment=NSTextAlignmentCenter;
_passField.placeholder=@"请输入密码6-12位";
_passField.secureTextEntry=YES;
[_passField setBorderStyle:UITextBorderStyleRoundedRect];
[self.view addSubview:_passField];

_quxiao=[[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2-60, 220, 75, 40)];
[_quxiao setTitle:@"取消注册" forState:UIControlStateNormal];
[_quxiao setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[_quxiao addTarget:self action:@selector(quxiao) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_quxiao];

_save=[[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2+40, 220, 55, 40)];
[_save setTitle:@"注册" forState:UIControlStateNormal];
[_save setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[_save addTarget:self action:@selector(userSave) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_save];
}
- (void) quxiao{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void) userSave{
NSString *name=[_nameField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSString *pass=[_passField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
UserCoreDate *user=[[UserCoreDate alloc]init];

UIAlertController *alert;
NSLog(@"%li,%li",name.length,pass.length);
if (name.length==0&&pass.length==0) {
alert=[UIAlertController alertControllerWithTitle:@"注册提示" message:@"输入不能为空" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleCancel handler:nil]];
[self presentViewController:alert animated:YES completion:nil];
return;
}
if (name.length>12||name.length<6) {
alert=[UIAlertController alertControllerWithTitle:@"注册提示" message:@"账号长度6-12位" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleCancel handler:nil]];
[self presentViewController:alert animated:YES completion:nil];
return;
}
if (pass.length>12||pass.length<6) {
alert=[UIAlertController alertControllerWithTitle:@"注册提示" message:@"密码长度6-12位" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleCancel handler:nil]];
[self presentViewController:alert animated:YES completion:nil];
return;
}

if([[user selectUser:name] count]!=0){
alert=[UIAlertController alertControllerWithTitle:@"注册提示" message:@"账号已经注册过,请重新输入" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleCancel handler:nil]];
[self presentViewController:alert animated:YES completion:nil];
return;
}

if ([user addUser:name :pass]) {
alert=[UIAlertController alertControllerWithTitle:@"注册提示" message:@"注册成功" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){
[self dismissViewControllerAnimated:YES completion:nil];
}]];
[self presentViewController:alert animated:YES completion:nil];

}else{
alert=[UIAlertController alertControllerWithTitle:@"注册提示" message:@"注册失败" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleCancel handler:nil]];
[self presentViewController:alert animated:YES completion:nil];
return;
}

}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

@end

//
// DailyViewController.m
// 动漫小屋
//
// Created by dc0061 on 15/12/16.
// Copyright © 2015年 dc0061. All rights reserved.
//

#import "DailyViewController.h"
#import "MyCellTableViewCell.h"
#import "MoreViewController.h"
#import "DetailedViewController.h"
#import "DetailedCroeDate.h"
#import "Detailed.h"

@interface DailyViewController ()<UITableViewDataSource,UITableViewDelegate>
{
UIImageView *_image;
UITableView *_tableView;
NSArray *_array;

UIView *_view;
UILabel *_headerTitle;
UIButton *_more;
NSUserDefaults *user;

NSMutableDictionary *_moredic;//存放所有的数据
NSArray *_moreArray;//得到字典里。对应键值
NSArray *_detaArray;//查询数据库得到的数据
DetailedCroeDate *d1;
}
@end

@implementation DailyViewController
- (void) viewDidAppear:(BOOL)animated{

d1=[[DetailedCroeDate alloc]init];
_moredic=[[NSMutableDictionary alloc]initWithCapacity:10];
for (int i=0; i<[_array count]; i++) {
_detaArray =[d1 selectDetailedLine:_array[i]];
[_moredic setValue: _detaArray forKey:_array[i]];
}
[_tableView reloadData];
}
- (void)viewDidLoad {
[super viewDidLoad];
user=[NSUserDefaults standardUserDefaults];
self.navigationItem.title=@"动漫日报";
_array=@[@"情报咨询",@"推荐",@"盘点",@"图集"];
_image = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 375, 164)];
_image.image=[UIImage imageNamed:@"48754"];
[self.view addSubview:_image];

_tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 164, 375, self.view.frame.size.height-214) style:UITableViewStyleGrouped];
_tableView.dataSource=self;
_tableView.delegate=self;
_tableView.backgroundColor=[UIColor colorWithRed:0.8 green:0.9 blue:0.8 alpha:0.6];
[self.view addSubview:_tableView];
[_tableView reloadData];
d1=[[DetailedCroeDate alloc]init];
_moredic=[[NSMutableDictionary alloc]initWithCapacity:10];
for (int i=0; i<[_array count]; i++) {
_detaArray =[d1 selectDetailedLine:_array[i]];
[_moredic setValue: _detaArray forKey:_array[i]];
}
}

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
MyCellTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell==nil) {
cell=[[MyCellTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
_moreArray=[_moredic objectForKey:_array[indexPath.section]];
Detailed *d=_moreArray[indexPath.row];
cell.context.text=d.context;
cell.author.text=d.author;

cell.context.numberOfLines=3;//多行显示
return cell;
}

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if ([[_moredic objectForKey:_array[section]] count]>3) {
return 2;
}else{
return [[_moredic objectForKey:_array[section]] count];
}
}

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
return [_array count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 100.0f;
}
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 30.0f;
}

- (CGFloat) tableView:(UITableView *)tableView estimatedHeightForFooterInSection:(NSInteger)section{
return 0;
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
_view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 375, 30)];
_headerTitle=[[UILabel alloc]initWithFrame:CGRectMake(20, 0, 80, 30)];
_headerTitle.text=_array[section];
[_view addSubview:_headerTitle];

_more=[[UIButton alloc]initWithFrame:CGRectMake(305, 0, 60, 30)];
[_more setTitle:@"更多>>" forState:UIControlStateNormal];
[_more setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[_more addTarget:self action:@selector(more:) forControlEvents:UIControlEventTouchUpInside];
_more.tag=section;
[_view addSubview:_more];
_view.backgroundColor=[UIColor colorWithRed:0.8 green:0.6 blue:0.8 alpha:0.9];
return _view;
}
//查看更多
- (void) more:(UIButton *) button{
[user setValue:[NSString stringWithFormat:@"%li",button.tag] forKey:@"daily_button_tag"];
MoreViewController *more=[[MoreViewController alloc]init];
[self.navigationController pushViewController:more animated:YES];
}

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[user setValue:@"YES" forKey:@"bool"];
DetailedViewController *detailed=[[DetailedViewController alloc]init];
[self.navigationController pushViewController:detailed animated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

@end

//More

//
// MoreViewController.m
// 动漫小屋
//
// Created by dc0061 on 15/12/17.
// Copyright © 2015年 dc0061. All rights reserved.
//

#import "MoreViewController.h"
#import "MyCellTableViewCell.h"
#import "DetailedViewController.h"
#import "DetailedCroeDate.h"
#import "Detailed.h"

@interface MoreViewController ()
{
UITableView *_tableView;

NSArray *_array;//类别数组
NSMutableDictionary *_dic;//数据库返回的时间字典
NSMutableDictionary *_moredic;//存放所有的数据
NSArray *_MoreArray;//数据库返回字典的所有值
NSArray *_detaArray;//查询数据库得到的数据
NSUserDefaults *user;
DetailedCroeDate *d1;
}
@end

@implementation MoreViewController

- (void)viewDidLoad {
[super viewDidLoad];
_array=@[@"情报咨询",@"推荐",@"盘点",@"图集"];
user=[NSUserDefaults standardUserDefaults];
int num=[[user objectForKey:@"daily_button_tag"] intValue];
if ([user objectForKey:@"daily_button_tag"]==nil) {
self.navigationItem.title=@"我的参与";
d1=[[DetailedCroeDate alloc]init];
_dic=[d1 selectDetailedTime:[user objectForKey:@"userName"]];//获取到时间字典
_MoreArray=[_dic allValues];//获取所有字典里面的时间值

_moredic=[[NSMutableDictionary alloc]initWithCapacity:10];
for (int i=0; i<[_MoreArray count]; i++) {
_detaArray =[d1 selectDetailedAuthor:[user objectForKey:@"userName"] :_MoreArray[i]];
[_moredic setValue: _detaArray forKey:_MoreArray[i]];
}
}else{
self.navigationItem.title=_array[num];
d1=[[DetailedCroeDate alloc]init];
_dic=[d1 DetailedTime:_array[num]];//获取到时间字典
NSLog(@"dic%@",_dic);
_MoreArray=[_dic allValues];//获取所有字典里面的时间值
_moredic=[[NSMutableDictionary alloc]initWithCapacity:10];
for (int i=0; i<[_MoreArray count]; i++) {
_detaArray =[d1 selectDetailedLineTime:_array[num] :_MoreArray[i]];
[_moredic setValue: _detaArray forKey:_MoreArray[i]];
}
}
_tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 375, 667) style:UITableViewStyleGrouped];
_tableView.delegate=self;
_tableView.dataSource=self;
[self.view addSubview:_tableView];

}

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
MyCellTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell==nil) {
cell=[[MyCellTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
}
NSArray *array=[_moredic objectForKey:_MoreArray[indexPath.section]];
Detailed *d=array[indexPath.row];
//将查询到的数据添加到页面
cell.context.text=d.context;
cell.author.text=[NSString stringWithFormat:@"%@",d.author];
cell.context.numberOfLines=3;//多行显示
return cell;
}

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [[_moredic objectForKey:_MoreArray[section]] count];
}

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
return [_MoreArray count];
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 100;
}

- (NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{

return _MoreArray[section];
}

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSArray *array=[_moredic objectForKey:_MoreArray[indexPath.section]];
Detailed *dd=array[indexPath.row];
NSArray *a=@[dd.context,dd.author];
[user setValue:a forKey:@"zhi"];
[user setValue:@"YES" forKey:@"bool"];
DetailedViewController *detailed=[[DetailedViewController alloc]init];
[self.navigationController pushViewController:detailed animated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

@end

//Detail

//
// DetailedViewController.m
// 动漫小屋
//
// Created by dc0061 on 15/12/17.
// Copyright © 2015年 dc0061. All rights reserved.
//

#import "DetailedViewController.h"
#import "DetailedCroeDate.h"
#import "Detailed.h"
#import "DailyViewController.h"
#import "LoginViewController.h"
@interface DetailedViewController ()
{
UILabel *_label;
UIButton *_fanhui;//返回
UIImageView *_image;
UITextView *_context;

NSUserDefaults *user;

NSArray *_array;//类别数组
NSMutableArray *_mutableArray;//类别数组按钮

//点击参与日报进入本页面,需要添加的控件
UILabel *_xuanze;//提示选中类别
UIButton *_line;//归类
UIButton *_tijiao;//发表的按钮

}
@end

@implementation DetailedViewController
static NSInteger i=5;
- (void)viewDidLoad {
[super viewDidLoad];
_array=@[@"情报咨询",@"推荐",@"盘点",@"图集"];
_image = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 375, 667)];
_image.image=[UIImage imageNamed:@"48754"];
[self.view addSubview:_image];

self.navigationItem.title=@"动态详情";
_label=[[UILabel alloc]initWithFrame:CGRectMake(60, 90, 200, 40)];
_label.text=@"作者:zxca";
_label.textColor=[UIColor blueColor];
[self.view addSubview:_label];

_fanhui = [[UIButton alloc]initWithFrame:CGRectMake(300, 90, 50, 40)];
[_fanhui setTitle:@"返回" forState:UIControlStateNormal];
[_fanhui setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[_fanhui addTarget:self action:@selector(fanhui) forControlEvents:UIControlEventTouchUpInside];
[_fanhui setBackgroundColor:[UIColor redColor]];
[self.view addSubview:_fanhui];

user=[ NSUserDefaults standardUserDefaults];
int num=0;
if ([user objectForKey:@"bool"]==nil) {
num=50;
//点击参与日报后执行的方法
[self part];
}
_context =[[UITextView alloc]initWithFrame:CGRectMake(20, 140+num, 335, 400-num)];
_context.font=[UIFont fontWithName:@"Arial" size:20];
if ([user objectForKey:@"bool"]==nil) {
_context.editable=YES;//设置读写
_label.text=[NSString stringWithFormat:@"作者:%@",[user objectForKey:@"userName"]];
_fanhui.hidden=NO;
}else{
NSArray *deta=[user objectForKey:@"zhi"];
_context.text=deta[0];
_label.text=[NSString stringWithFormat:@"作者:%@",deta[1]];
_context.editable=NO;//设置只读
_context.backgroundColor=[UIColor clearColor];
_fanhui.hidden=YES;
}
[self.view addSubview:_context];

}
//点击参与日报后执行的方法
- (void) part{
_xuanze=[[UILabel alloc]initWithFrame:CGRectMake(20, 140, 90, 40)];
_xuanze.text=@"请选择类别:";
[self.view addSubview:_xuanze];
_mutableArray=[[NSMutableArray alloc]init];
for (int i=0; i<4; i++) {
if ([_array[i] length]>2) {
_line=[[UIButton alloc]initWithFrame:CGRectMake(120+40*i, 140, 80, 40)];
}else{
_line=[[UIButton alloc]initWithFrame:CGRectMake(160+50*i, 140, 40, 40)];
}
[_line setTitle:_array[i] forState:UIControlStateNormal];
[_line setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
_line.tag=i;
[_line addTarget:self action:@selector(line:) forControlEvents:UIControlEventTouchUpInside];
[_mutableArray addObject:_line];
[self.view addSubview:_line];
}
_tijiao=[[UIButton alloc]initWithFrame:CGRectMake(300, 560, 60, 40)];
[_tijiao setTitle:@"提交" forState:UIControlStateNormal];
[_tijiao setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[_tijiao setBackgroundColor:[UIColor redColor]];
[_tijiao addTarget:self action:@selector(tijiao) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_tijiao];
}

- (void) line:(UIButton *) sender{
i=sender.tag;
for (int j=0; j<[_mutableArray count]; j++) {
if (j==sender.tag) {
[_mutableArray[j] setBackgroundColor:[UIColor redColor]];
}else{
[_mutableArray[j] setBackgroundColor:nil];
}
}
}

- (void) tijiao{
if (i==5) {
UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"提示" message:@"请选择类别" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleCancel handler:nil]];
[self presentViewController:alert animated:NO completion:nil];

return;
}
if ([_context.text length]==0) {
UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"提示" message:@"内容不能为空" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleCancel handler:nil]];
[self presentViewController:alert animated:NO completion:nil];

return;
}
DetailedCroeDate *deta=[[DetailedCroeDate alloc]init];
if ([deta addDetailed:[user objectForKey:@"userName"] :_array[i] : _context.text:@"2"]) {
i=5;
UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"登陆提示" message:@"发表成功" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
[self dismissViewControllerAnimated:NO completion:nil];
}]];
[self presentViewController:alert animated:YES completion:nil];
}else{
NSLog(@"发表失败");
}
}

- (void) fanhui{
[self dismissViewControllerAnimated:NO completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

@end

//TabBar

//
// TabBarViewController.m
// 动漫小屋
//
// Created by dc0061 on 15/12/19.
// Copyright © 2015年 dc0061. All rights reserved.
//

#import "TabBarViewController.h"
#import "HomeView.h"
#import "DailyViewController.h"
#import "LoginViewController.h"
#import "ViewController.h"

@interface TabBarViewController ()

@end

@implementation TabBarViewController

- (void)viewDidLoad {
[super viewDidLoad];
ViewController *view = [[ViewController alloc]init];
LoginViewController *login=[[LoginViewController alloc]init];
DailyViewController *daily=[[DailyViewController alloc]init];
//设置顶部导航栏

UINavigationController *loginNav=[[UINavigationController alloc]initWithRootViewController:login];

UINavigationController *dailyNav=[[UINavigationController alloc]initWithRootViewController:daily];
//设置底部分页导航名称
view.tabBarItem.title=@"首页";
view.tabBarItem.image=[UIImage imageNamed:@"home"];

loginNav.tabBarItem.title=@"我的";
loginNav.tabBarItem.image=[UIImage imageNamed:@"my"];

dailyNav.tabBarItem.title=@"日报";
dailyNav.tabBarItem.image=[UIImage imageNamed:@"rbao"];
//实例化导航控制器
self.viewControllers =@[view,dailyNav,loginNav];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

@end

//APPdelegate

//
// AppDelegate.m
// 动漫小屋
//
// Created by dc0061 on 15/12/15.
// Copyright © 2015年 dc0061. All rights reserved.
//

#import "AppDelegate.h"
#import "HomeView.h"
@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window.backgroundColor=[UIColor whiteColor];
HomeView *home = [[HomeView alloc]init];

self.window.rootViewController=home;

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: