動漫小屋

//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
app










//
//  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

ide




//Moreui

//
//  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

this






//Detailspa

//
//  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
.net





//TabBarrest

//
//  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

orm


//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

相關文章
相關標籤/搜索