欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS開發(fā)的UI制作中動(dòng)態(tài)和靜態(tài)單元格的基本使用教程

 更新時(shí)間:2015年12月16日 09:46:17   作者:文頂頂  
這篇文章主要介紹了iOS開發(fā)的UI制作中動(dòng)態(tài)和靜態(tài)單元格的基本使用教程,代碼基于傳統(tǒng)的Objective-C,需要的朋友可以參考下

靜態(tài)單元格的使用
一、實(shí)現(xiàn)效果與說(shuō)明

2015121693950758.png (320×501)

說(shuō)明:觀察上面的展示效果,可以發(fā)現(xiàn)整個(gè)界面是由一個(gè)tableview來(lái)展示的,上面的數(shù)據(jù)都是固定的,且?guī)缀醪粫?huì)改變。

要完成上面的效果,有幾種方法:

(1)可以直接利用代碼,返回三組,在判斷每組有多少行,展示些什么數(shù)據(jù),這樣寫“死”的代碼建議絕不要使用。

(2)稍微靈活一些的,可以把plist文件一懶加載的方式,加載到程序中,動(dòng)態(tài)獲取。但是觀察界面結(jié)構(gòu),很容易看出這樣需要進(jìn)行模型嵌套,很麻煩。

(3)storyboard提供了靜態(tài)單元格這個(gè)功能,可以很方便的完成上面的界面展示效果。(提示:在實(shí)際的開發(fā)中很少這樣使用)

二、使用靜態(tài)單元格完成簡(jiǎn)單界面展示的過(guò)程

在類似的開發(fā)中,如果整個(gè)界面都是tableview,那么直接讓控制器繼承自UItableviewcontroller.

修改主控制器,讓其繼承自UItableviewcontroller

2015121694025433.png (676×150)

把storyboard中默認(rèn)的uiview刪掉,直接拖一個(gè)viewcontroller

2015121694049342.png (846×582)

當(dāng)拖入一個(gè)viewcontroller的時(shí)候,它上面默認(rèn)就會(huì)有一個(gè)cell,默認(rèn)情況下,這個(gè)cell是動(dòng)態(tài)的,也就是默認(rèn)是看不見(jiàn)的。

把cell設(shè)置成靜態(tài)的,在屬性面板的content  中設(shè)置為static cell(靜態(tài)cell)所見(jiàn)即所得  注意必須更改這里的這個(gè)屬性。

2015121694108022.png (778×176)

讓它和主控制器關(guān)聯(lián)

2015121694126400.png (767×172)

接下來(lái),可以依次設(shè)置顯示的圖片和文字。

設(shè)置標(biāo)題有兩種方式:

1是雙擊更改

2015121694152622.png (385×107)

2是點(diǎn)擊子控件  lable修改

2015121694207921.png (1115×174)

按照界面需要,設(shè)置輔助視圖

2015121694224070.png (715×109)

設(shè)置有多少組,每組有多少行。
設(shè)置組:
點(diǎn)擊tableview   設(shè)置屬性面板的sections屬性。

2015121694243280.png (992×264)

設(shè)置每組多少行:

2015121694300303.png (1008×390)

小技巧:如果寫的單元格千年不變,那么可以先寫一組中的一行,再拷貝,稍作修改即可。
注意:靜態(tài)單元格是實(shí)際開發(fā)中,很少用到,此處只當(dāng)知識(shí)點(diǎn)介紹。


在UITableview的應(yīng)用中使用動(dòng)態(tài)單元格來(lái)完成app應(yīng)用程序管理界面的搭建
一、實(shí)現(xiàn)效果

2015121694318055.png (640×960)

說(shuō)明:該示例在storyboard中使用動(dòng)態(tài)單元格來(lái)完成。

二、實(shí)現(xiàn)

1.項(xiàng)目文件結(jié)構(gòu)和plist文件

2015121694333357.png (732×412)

2.實(shí)現(xiàn)過(guò)程以及代碼

2015121694351144.png (262×141)

在tableview的屬性選擇器中選擇動(dòng)態(tài)單元格。

2015121694407505.png (1085×209)

說(shuō)明:在storyboard中直接使用其自帶的動(dòng)態(tài)單元格完成tableviewcell的定義,并創(chuàng)建了一個(gè)管理該cell的類,進(jìn)行了連線。

實(shí)現(xiàn)代碼:

數(shù)據(jù)模型部分:

YYappInfo.h文件

復(fù)制代碼 代碼如下:

//
//  YYappInfo.h
//  01-使用動(dòng)態(tài)單元格來(lái)完成app應(yīng)用程序管理界面的搭建
//
//  Created by 孔醫(yī)己 on 14-6-2.
//  Copyright (c) 2014年 itcast. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface YYappInfo : NSObject
@property(nonatomic,copy)NSString *size;
@property(nonatomic,copy)NSString *download;
@property(nonatomic,copy)NSString *icon;
@property(nonatomic,copy)NSString *name;

-(instancetype)initWithDict:(NSDictionary *)dict;
+(instancetype)appInfoWithDict:(NSDictionary *)dict;
@end


YYappInfo.m文件
復(fù)制代碼 代碼如下:

//
//  YYappInfo.m
//  01-使用動(dòng)態(tài)單元格來(lái)完成app應(yīng)用程序管理界面的搭建
//
//  Created by 孔醫(yī)己 on 14-6-2.
//  Copyright (c) 2014年 itcast. All rights reserved.
//

#import "YYappInfo.h"

@implementation YYappInfo

-(instancetype)initWithDict:(NSDictionary *)dict
{
    if (self=[super init]) {
        //使用KVC
        [self setValuesForKeysWithDictionary:dict];
    }
    return self;
}


+(instancetype)appInfoWithDict:(NSDictionary *)dict
{

    return [[self alloc]initWithDict:dict];
}
@end


視圖部分

 YYappCell.h文件

復(fù)制代碼 代碼如下:

//
//  YYappCell.h
//  01-使用動(dòng)態(tài)單元格來(lái)完成app應(yīng)用程序管理界面的搭建
//
//  Created by 孔醫(yī)己 on 14-6-2.
//  Copyright (c) 2014年 itcast. All rights reserved.
//

#import <UIKit/UIKit.h>


@class YYappInfo,YYappCell;

@protocol YYappCellDelegate <NSObject>
-(void)btnDidClick:(YYappCell *)cell;


@end
@interface YYappCell : UITableViewCell

@property(nonatomic,strong)YYappInfo *app;
//@property(nonatomic,strong)YYViewController *controller;
@property(nonatomic,strong)id <YYappCellDelegate> delegate;

@end


YYappCell.m文件
復(fù)制代碼 代碼如下:

//
//  YYappCell.m
//  01-使用動(dòng)態(tài)單元格來(lái)完成app應(yīng)用程序管理界面的搭建
//
//  Created by 孔醫(yī)己 on 14-6-2.
//  Copyright (c) 2014年 itcast. All rights reserved.
//

#import "YYappCell.h"
#import "YYappInfo.h"

@interface YYappCell ()
@property (weak, nonatomic) IBOutlet UIImageView *appimg;

@property (weak, nonatomic) IBOutlet UILabel *apptitle;
@property (weak, nonatomic) IBOutlet UILabel *appdownload;
@property (weak, nonatomic) IBOutlet UIButton *appbtn;

@end


復(fù)制代碼 代碼如下:

@implementation YYappCell


-(void)setApp:(YYappInfo *)app
{
    _app=app;
    self.apptitle.text=_app.name;
    self.appdownload.text=[NSString stringWithFormat:@"大小 %@ | 下載量 %@次",_app.size,_app.download];
    self.appimg.image=[UIImage imageNamed:_app.icon];
   
}

#pragma mark- 完成按鈕點(diǎn)擊事件

- (IBAction)btnOnclick:(UIButton *)sender
{
    //按鈕被點(diǎn)擊后,變?yōu)椴豢捎脿顟B(tài)
    sender.enabled=NO;
   
    //通知代理,完成提示下載已經(jīng)完成的動(dòng)畫效果
    if ([self.delegate respondsToSelector:@selector(btnDidClick:)]) {
        //一般而言,誰(shuí)觸發(fā)就把誰(shuí)傳過(guò)去
        [self.delegate  btnDidClick:self];
    }
}

@end


主控制器

YYViewController.m文件

復(fù)制代碼 代碼如下:

//
//  YYViewController.m
//  01-使用動(dòng)態(tài)單元格來(lái)完成app應(yīng)用程序管理界面的搭建
//
//  Created by 孔醫(yī)己 on 14-6-2.
//  Copyright (c) 2014年 itcast. All rights reserved.
//

#import "YYViewController.h"
#import "YYappInfo.h"
#import "YYappCell.h"

@interface YYViewController ()<UITableViewDataSource,YYappCellDelegate>
@property(nonatomic,strong)NSArray *apps;
@property (strong, nonatomic) IBOutlet UITableView *tableview;

@end


復(fù)制代碼 代碼如下:

@implementation YYViewController

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

#pragma mark- 使用懶加載先把plist文件中得數(shù)據(jù)加載進(jìn)來(lái)
-(NSArray *)apps
{
    if (_apps==Nil) {
        NSString *fullpath=[[NSBundle mainBundle]pathForResource:@"apps_full.plist" ofType:Nil];
        NSArray *arrayM=[NSArray arrayWithContentsOfFile:fullpath];
       
        NSMutableArray *modles=[NSMutableArray arrayWithCapacity:arrayM.count];
        for (NSDictionary *dict in arrayM) {
            YYappInfo *appinfo=[YYappInfo appInfoWithDict:dict];
            [modles addObject:appinfo];
        }
        _apps=[modles copy];
    }
    return _apps;
}


#pragma mark- 設(shè)置tableview的數(shù)據(jù)源方法
//組
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
//行
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.apps.count;
}
//組-行-數(shù)據(jù)
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //創(chuàng)建cell
    static NSString *identifier=@"app";
    YYappCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
    //設(shè)置cell的數(shù)據(jù)
    YYappInfo *appinfo=self.apps[indexPath.row];
    //設(shè)置代理
    cell.delegate=self;
    cell.app=appinfo;
    //返回cell
    return cell;
}

#pragma mark- 設(shè)置代理
-(void)btnDidClick:(YYappCell *)cell
{
    //取出模型
    YYappInfo *app=cell.app;
    NSLog(@"daili");
    UILabel *lab=[[UILabel alloc]init];
    //提示的顯示位置
    lab.frame=CGRectMake(60, 300, 200, 20);
    //設(shè)置提示文本
    lab.text=[NSString stringWithFormat:@"%@已經(jīng)下載完成",app.name];
    //設(shè)置文本背景顏色
    [lab setBackgroundColor:[UIColor grayColor]];
    [self.view addSubview:lab];
    lab.alpha=1.0;
   
    //設(shè)置動(dòng)畫效果
    [UIView animateWithDuration:2.0 animations:^{
        lab.alpha=0.0;
    } completion:^(BOOL finished) {
        //把彈出的提示信息從父視圖中刪除
        [lab removeFromSuperview];
    }];
}

#pragma mark-隱藏狀態(tài)欄
-(BOOL)prefersStatusBarHidden
{
    return YES;
}

@end


補(bǔ)充說(shuō)明

  在程序中通過(guò)標(biāo)示符取出對(duì)應(yīng)的cell,是因?yàn)樵趕toryboard中已經(jīng)對(duì)cell打上了標(biāo)示符(app)的標(biāo)簽。

復(fù)制代碼 代碼如下:

//組-行-數(shù)據(jù)
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //創(chuàng)建cell
    static NSString *identifier=@"app";
    YYappCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
    //設(shè)置cell的數(shù)據(jù)
    YYappInfo *appinfo=self.apps[indexPath.row];
    //設(shè)置代理
    cell.delegate=self;
    cell.app=appinfo;
    //返回cell
    return cell;
}

2015121694429191.png (730×145)

相關(guān)文章

最新評(píng)論