美食屋-iosプロジェクトソース-tableViewのパッケージ


我々はカプセル化を学び,徐々にカプセル化の思想を育成しなければならない.
これは私たちのプロジェクト開発に役立ちます.
プロジェクトの成否の一つはアイデアであり、もう一つはコードの品質である.
市場でのプロジェクトはたくさんあると思いますが、本当に試練を経験できるソフトウェアは多くありません.
プロジェクト開発には重要な要素があるからです.
私たちが開発したプロジェクトはmvcの思想で私たちのコードを設計しなければなりません.
これは後期のプロジェクトのアップグレードとメンテナンスに大きなトラブルをもたらします.
一つのプロジェクトの流産の有無はこの要素と密接に関連している.
だから私たちは良い符号化習慣を身につけなければなりません
これは会社のプロジェクトの開発にとって重要な意義があります.
良いコードスタイルとコード習慣は私たちの開発を便利にしました.
簡単な例を挙げる
私たちのチームはプロジェクトを開発しています.プロジェクトサイクルは3ヶ月です.
1ヶ月が過ぎた後、あるメンバーが退職します.
これはチーム全体に大きな迷惑をかけた.
この人が書いたコードはコントローラに積み上げられていて、数千行のコードがあります.
他の人が理解しても数百個のバグを修正するのに長い時間がかかります
では、mvcのアイデアを使ってプロジェクトを開発することができます.
すべてのプロジェクトがmvcを使うわけではありませんが、これは私たちの大きな困難を解決しました.
我々の開発プロジェクトでは、すべてのモジュールを1つのコンポーネントと見なすことができます.
使用時にコントローラに装着
使用しない場合は削除します
このようなコードメンテナンスはソフトウェアのアップグレードとかなりメリットがあります.
今日この小さなプロジェクトは前の編を引き継いで書いたものです.
tableViewをパッケージングし、ここではtableViewのパッケージングのみが貼られています
コントローラのコードが少なくきれいになっているのがわかります
このような開発プログラムは私たちに多くのメリットをもたらし、他の人にも迷惑をかけません.
//
//  QHContentView.h
//   
//


#import <UIKit/UIKit.h>


@interface QHContentView : UIView
// 

@property(nonatomic,strong)NSArray *subject;
+(instancetype)contentView;
@end
//
//  QHContentView.m
//   
//


#import "QHContentView.h"
#import "QHSubjectCell.h"
#import "QHAdsView.h"


@interface QHContentView()<UITableViewDataSource,QHAdsViewDelegate,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;


@end

@implementation QHContentView


+(instancetype)contentView
{
    return [[[NSBundle mainBundle]loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil]lastObject] ;
}


-(void)setSubject:(NSArray *)subject
{
    _subject = subject;
    
    // UI  
    [self.tableView reloadData];

}
// xib  
-(void)awakeFromNib
{
    QHAdsView *adsView = [QHAdsView adsView];
    
    //[self.view addSubview:adsView];
    self.tableView.tableHeaderView = adsView;
    //    self.tableView.delegate = self;
    //    self.tableView.dataSource = self;
    
    
    
    adsView.images = @[@"ad_00",@"ad_01",@"ad_02",@"ad_03",@"ad_04"];
    adsView.delegate = self;

}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.subject.count;
}

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

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    QHSubjectCell *cell = [QHSubjectCell subjectCellWithTableView:tableView];
    
    cell.subject = self.subject[indexPath.row];
    
    return cell;

}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}
/*
 
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
#import "ViewController.h"
#import "QHAdsView.h"
#import "QHSubject.h"
#import "QHSubjectCell.h"
#import "QHContentView.h"

@interface ViewController ()<QHAdsViewDelegate,UITableViewDataSource,UITableViewDelegate>


@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property(nonatomic,strong)NSArray *plist;
@property(nonatomic,strong)NSArray *subject;



@end

@implementation ViewController

//      
//  , , 

-(NSArray *)plist
{
    if (_plist == nil) {
        NSString *path = [[NSBundle mainBundle]pathForResource:@"quanquan.plist" ofType:nil];
        NSArray *array = [NSArray arrayWithContentsOfFile:path];
        
        _plist = array;
        
    }
    return _plist;
}

-(NSArray *)subject
{
    if (_subject == nil) {
        NSArray *dicts = self.plist[1];
        NSMutableArray *objs = [NSMutableArray array];
        
        for(NSDictionary *dict in dicts)
        {
            //kvc   
            QHSubject *subject = [QHSubject subjectWithDict:dict];
            // 
            [objs addObject:subject];
        }
        _subject = objs;
    }
    return _subject;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    QHContentView *contentView = [QHContentView contentView];
    
    [self.view addSubview:contentView];
    
    contentView.subject = self.subject;
    
    
//    QHAdsView *adsView = [QHAdsView adsView];
//    
//    //[self.view addSubview:adsView];
//    self.tableView.tableHeaderView = adsView;
////    self.tableView.delegate = self;
////    self.tableView.dataSource = self;
//    
//
//    
//    adsView.images = @[@"ad_00",@"ad_01",@"ad_02",@"ad_03",@"ad_04"];
//    adsView.delegate = self;
//    
//    
//    [adsView setAdsViewDidSelected:^(QHAdsView * adsView, NSString * image, NSInteger index) {
//        NSLog(@"%@&&&&&&",image);
//    }];
    // Do any additional setup after loading the view, typically from a nib.
}

//-(void)adsViewDidSelected:(QHAdsView *)adsView andImage:(NSString *)image andIndex:(NSInteger)index
//{
//    NSLog(@"%@",NSStringFromSelector(_cmd));
//}


//- (void)didReceiveMemoryWarning {
//    [super didReceiveMemoryWarning];
//    // Dispose of any resources that can be recreated.
//}
//
//#pragma mark UITableViewDelegate
//
//-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
//{
//    return self.subject.count;
//}
//
//
//
//-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    /*
//    static NSString *cellName = @"cell";
//    
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
//    
//    if (cell == nil) {
//        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellName];
//    }
//    cell.textLabel.text = @"text";
//    return cell;
//     */
//    
//    QHSubjectCell *cell = [QHSubjectCell subjectCellWithTableView:tableView];
//    
//    cell.subject = self.subject[indexPath.row];
//    
//    NSLog(@"%@",cell.subject);
//    
//    return cell;
//}
//-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    return 100;
//}

@end