国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

IOS開發(fā)UI篇--UITableView的自定義布局==xib布局

2019-11-14 20:27:24
字體:
供稿:網(wǎng)友

利用Xib進(jìn)行實現(xiàn)

應(yīng)用場景:像團(tuán)購網(wǎng)站的列表數(shù)據(jù)顯示,新聞列表顯示等(由于該類的顯示的數(shù)據(jù)單元格內(nèi)容格式相同)

(1)主控制器文件,在文件中實現(xiàn)了自己自定義的代理,加載數(shù)據(jù),

 1 #import "SLViewController.h" 2 #import "SLTgDatas.h" 3 #import "SLTableViewCell.h" 4 #import "SLFooterView.h" 5 #import "SLHeaderView.h" 6  7 @interface SLViewController ()<UITableViewDataSource,UITableViewDelegate,SLFooterViewDelegate> 8  9 @PRoperty (weak, nonatomic) IBOutlet UITableView *tableview;10 11 @property (nonatomic,strong) NSMutableArray *arrayM;12 13 @end14 15 @implementation SLViewController16 17 -(void)loadMoreData18 {19     NSLog(@"=======");20     SLTgDatas *da=[[SLTgDatas alloc] init];21     da.title=@"西紅柿雞蛋";22     da.price=@"12";23     da.buyCount=@"56";24     da.icon=@"2c97690e72365e38e3e2a95b934b8dd2";25     [self.arrayM  addObject:da];26     [self.tableview reloadData];27     28 }29 30 31 #pragma mark -解析plist數(shù)據(jù)文件32 -(NSMutableArray *)arrayM33 {34     if (_arrayM==nil) {35         NSString *fullpath=[[NSBundle mainBundle] pathForResource:@"tgs" ofType:@"plist"];36         NSArray *array=[NSArray arrayWithContentsOfFile:fullpath];37         NSMutableArray *arr=[NSMutableArray arrayWithCapacity:array.count];38         for (NSDictionary *dict in array) {39             SLTgDatas *data=[SLTgDatas tgDataWithDiectionary:dict];40             [arr addObject:data];41         }42        43         _arrayM=arr;44     }45  46     return _arrayM;47 }48 49 - (void)viewDidLoad50 {51     [super viewDidLoad];52    // self.tableview.dataSource=self;53     54     UINib *nib=[UINib nibWithNibName:@"SLFooterView" bundle:nil];55     SLFooterView *footerview=[[nib instantiateWithOwner:nil options:nil] firstObject];56     self.tableview.tableFooterView=footerview;57     58     footerview.delegate=self;59     60     SLHeaderView *headerview=[SLHeaderView headerWithView];61     self.tableview.tableHeaderView=headerview;62    63 }64 65 #pragma mark -填充數(shù)據(jù)進(jìn)行顯示66 -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView67 {68     return 1;69 }70 71 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section72 {73     return self.arrayM.count;74 }75 76 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath77 {78     SLTableViewCell  *cell=[SLTableViewCell cellWithTabelViewCell:tableView];79     SLTgDatas *data=self.arrayM[indexPath.row];80     cell.data=data;81     return cell;82 }83 84 #pragma mark -設(shè)置狀態(tài)欄隱藏85 -(BOOL)prefersstatusBarHidden86 {87     return YES;88 }89 90 @end

 

(2)該文件是字典轉(zhuǎn)對象模型文件

 1 #import <Foundation/Foundation.h> 2  3 #import "SLGlobalCode.h" 4  5 @interface SLTgDatas : NSObject 6  7 @property (nonatomic,copy) NSString *title; 8 @property (nonatomic,copy) NSString *icon; 9 @property (nonatomic,copy) NSString *price;10 @property (nonatomic,copy) NSString *buyCount;11 12 @property (nonatomic,strong,readonly) UIImage *image;13 14 //SLTg(tg)15 -(instancetype)initWithTgDirectionary:(NSDictionary *)dict;16 17 +(instancetype)tgDataWithDiectionary:(NSDictionary *)dict;18 @end
 1 #import "SLTgDatas.h" 2  3 @interface SLTgDatas () 4 { 5     UIImage *_image; 6 } 7 @end 8  9 @implementation SLTgDatas10 11 -(UIImage *)image12 {13     if (_image==nil) {14         _image=[UIImage imageNamed:self.icon];15     }16     return _image;17 }18 /**19  *  對代碼進(jìn)行抽取,成為其他地方也可以用這個方法20  */21 //SLTgRetrun(tg)22 -(instancetype)initWithTgDirectionary:(NSDictionary *)dict23 {24     if (self=[self init]) {25        [self setValuesForKeysWithDictionary:dict];26     }27     return self;28 }29 +(instancetype)tgDataWithDiectionary:(NSDictionary *)dict30 {31     return [[self alloc] initWithTgDirectionary:dict];32 }33 @end

 

(3)此文件是自定義cell對象,通過xib進(jìn)行設(shè)計后,通過連線進(jìn)行相關(guān),方便控制器調(diào)用

 1 #import <UIKit/UIKit.h> 2  3 #import "SLTgDatas.h" 4  5 @interface SLTableViewCell : UITableViewCell 6  7 @property (nonatomic,strong) SLTgDatas *data; 8  9 +(instancetype)cellWithTabelViewCell:(UITableView *)table;10 11 @end
#import "SLTableViewCell.h"@interface SLTableViewCell()@property (weak, nonatomic) IBOutlet UIImageView *cellImage;@property (weak, nonatomic) IBOutlet UILabel *celltitle;@property (weak, nonatomic) IBOutlet UILabel *cellprice;@property (weak, nonatomic) IBOutlet UILabel *cellbuycount;@end@implementation SLTableViewCell+(instancetype)cellWithTabelViewCell:(UITableView *)table{    static NSString *str=@"cell";    SLTableViewCell *cell=[table dequeueReusableCellWithIdentifier:str];    if (cell==nil) {        cell=[[[NSBundle mainBundle] loadNibNamed:@"SLTgPlistView" owner:nil                                          options:nil] firstObject];    }    return cell;}-(void)setData:(SLTgDatas *)data{    _data=data;    self.cellbuycount.text=data.buyCount;    self.cellImage.image=data.image;    self.cellprice.text=data.price;    self.celltitle.text=data.title;}@end

 

(4)是底部加載更多選項

 1 #import <UIKit/UIKit.h> 2  3 @protocol SLFooterViewDelegate <NSObject> 4  5 -(void)loadMoreData; 6  7 @end 8  9 @interface SLFooterView : UIView10 11 @property (nonatomic,weak) id<SLFooterViewDelegate> delegate;12 @end
 1     #import "SLFooterView.h" 2     @interface SLFooterView () 3  4     @property (weak, nonatomic) IBOutlet UIButton *clieckbt; 5     @property (weak, nonatomic) IBOutlet UIView *jiazai; 6  7  8  9     @end10     @implementation SLFooterView11 12     -(void)setDelegate:(id<SLFooterViewDelegate>)delegate13     {14         _delegate=delegate;15     }16 17     - (IBAction)btnclick {18         self.clieckbt.hidden=YES;19         self.jiazai.hidden=NO;20         21     //    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.022     // * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{23     //24     //    });25     //    26         dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{27             if ([self.delegate respondsToSelector:@selector(loadMoreData)])28                         {29                             [self.delegate loadMoreData];30                        }31                        self.clieckbt.hidden=NO;32                        self.jiazai.hidden=YES;33         });34        35         36     }37 38     @end

以上就是利用xib進(jìn)行設(shè)計的tableView進(jìn)行顯示的列表數(shù)據(jù)

綜上所述:在自定義UITabelViewCell的時候,有兩種方式,要根據(jù)不同的場景進(jìn)行利用。


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 廊坊市| 石柱| 友谊县| 浮山县| 玛纳斯县| 上思县| 张家川| 星座| 泽库县| 平凉市| 沙田区| 高唐县| 全椒县| 濮阳市| 汤阴县| 翁源县| 广宁县| 新建县| 饶平县| 获嘉县| 盐山县| 金阳县| 仙桃市| 砀山县| 隆安县| 星座| 剑阁县| 藁城市| 盐城市| 武穴市| 会宁县| 梅州市| 河源市| 嘉禾县| 紫金县| 邹平县| 昭通市| 沈丘县| 陵水| 陵水| 英吉沙县|