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

首頁(yè) > 系統(tǒng) > iOS > 正文

詳解ios中自定義cell,自定義UITableViewCell

2019-10-21 18:49:41
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

通過(guò)繼承UITableViewCell來(lái)自定義cell

1、創(chuàng)建一個(gè)空的項(xiàng)目、命名:

ios,uitableview,cell,uitableviewcell,自定義cellios,uitableview,cell,uitableviewcell,自定義cell

2、創(chuàng)建一個(gè)UITableViewController 并且同時(shí)創(chuàng)建xib:

ios,uitableview,cell,uitableviewcell,自定義cell

3、設(shè)置AppDelegate.m中window的根控制器為剛剛創(chuàng)建的TableViewController:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {   self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];   TableViewController *tableViewController = [[[TableViewController alloc] init] autorelease]; //自動(dòng)釋放   //設(shè)置根控制器   self.window.rootViewController = tableViewController;   [self.window makeKeyAndVisible];   return YES; } 

4、創(chuàng)建自定義的UITableViewCell:

ios,uitableview,cell,uitableviewcell,自定義cell

5、創(chuàng)建自定義cell的xib 拖放需要的控件
ios,uitableview,cell,uitableviewcell,自定義cell選擇User Interface。

ios,uitableview,cell,uitableviewcell,自定義cell創(chuàng)建空的xib。

ios,uitableview,cell,uitableviewcell,自定義cell拖入Cell控件。

ios,uitableview,cell,uitableviewcell,自定義cell完成自定義的cell控件。

ios,uitableview,cell,uitableviewcell,自定義cell設(shè)置cell控件的Identfier。

ios,uitableview,cell,uitableviewcell,自定義cell綁定Cell類(lèi)并且將控件的輸出口關(guān)聯(lián)到TableViewCell.h文件中。

6、對(duì)TableViewController類(lèi)編碼,在委托方法中設(shè)置自定義的Cell:

#import "TableViewController.h" #import "TableViewCell.h"  @interface TableViewController (){   NSMutableArray *tableData; //表格數(shù)據(jù) }  @end  @implementation TableViewController  - (id)initWithStyle:(UITableViewStyle)style {   self = [super initWithStyle:style];   if (self) {     // Custom initialization   }   return self; }  - (void)viewDidLoad {   [super viewDidLoad];   //初始化表格數(shù)據(jù)   tableData = [[NSMutableArray alloc] init];   for (int i = 0; i< 10; i++) {     [tableData addObject:[NSString stringWithFormat:@"MyCellDemon%i",i]];   }    //設(shè)置row的高度為自定義cell的高度   self.tableView.rowHeight = 90;   }  - (void)didReceiveMemoryWarning {   [super didReceiveMemoryWarning];  }  #pragma mark - Table view data source  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { #warning Potentially incomplete method implementation.    return 1; }  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { #warning Incomplete method implementation.    return [tableData count]; }  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {   //指定cellIdentifier為自定義的cell   static NSString *CellIdentifier = @"TableViewCell";   //自定義cell類(lèi)   TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];   if (cell == nil) {     //通過(guò)xib的名稱(chēng)加載自定義的cell     cell = [[[NSBundle mainBundle] loadNibNamed:@"TableViewCell" owner:self options:nil] lastObject];   }      //添加測(cè)試數(shù)據(jù)   cell.titleLabel.text = [tableData objectAtIndex:indexPath.row];   cell.content.text = @"這是一些測(cè)試數(shù)據(jù)";   //測(cè)試圖片   cell.iamge.image = [UIImage imageNamed:@"testImage.jpg"];    return cell; }  #pragma mark - Table view delegate  - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {  }  @end 

最終效果:

ios,uitableview,cell,uitableviewcell,自定義cell

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到IOS開(kāi)發(fā)頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 牙克石市| 广西| 尚志市| 顺昌县| 天津市| 长阳| 石景山区| 泰兴市| 灌云县| 威宁| 临安市| 丹寨县| 临颍县| 山东省| 海南省| 唐山市| 罗江县| 垦利县| 卢氏县| 沭阳县| 苗栗市| 文安县| 察哈| 剑川县| 玉林市| 苏州市| 浙江省| 清远市| 定远县| 泾源县| 兴国县| 镇安县| 柳河县| 电白县| 镇宁| 达尔| 栾城县| 武安市| 石渠县| 谢通门县| 城固县|