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

首頁 > 系統 > iOS > 正文

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

2020-07-26 03:01:29
字體:
來源:轉載
供稿:網友

通過繼承UITableViewCell來自定義cell

1、創建一個空的項目、命名:

2、創建一個UITableViewController 并且同時創建xib:

3、設置AppDelegate.m中window的根控制器為剛剛創建的TableViewController:

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

4、創建自定義的UITableViewCell:

5、創建自定義cell的xib 拖放需要的控件
選擇User Interface。

創建空的xib。

拖入Cell控件。

完成自定義的cell控件。

設置cell控件的Identfier。

綁定Cell類并且將控件的輸出口關聯到TableViewCell.h文件中。

6、對TableViewController類編碼,在委托方法中設置自定義的Cell:

#import "TableViewController.h" #import "TableViewCell.h"  @interface TableViewController (){   NSMutableArray *tableData; //表格數據 }  @end  @implementation TableViewController  - (id)initWithStyle:(UITableViewStyle)style {   self = [super initWithStyle:style];   if (self) {     // Custom initialization   }   return self; }  - (void)viewDidLoad {   [super viewDidLoad];   //初始化表格數據   tableData = [[NSMutableArray alloc] init];   for (int i = 0; i< 10; i++) {     [tableData addObject:[NSString stringWithFormat:@"MyCellDemon%i",i]];   }    //設置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類   TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];   if (cell == nil) {     //通過xib的名稱加載自定義的cell     cell = [[[NSBundle mainBundle] loadNibNamed:@"TableViewCell" owner:self options:nil] lastObject];   }      //添加測試數據   cell.titleLabel.text = [tableData objectAtIndex:indexPath.row];   cell.content.text = @"這是一些測試數據";   //測試圖片   cell.iamge.image = [UIImage imageNamed:@"testImage.jpg"];    return cell; }  #pragma mark - Table view delegate  - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {  }  @end 

最終效果:

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 从江县| 南澳县| 西丰县| 九寨沟县| 西乡县| 宝清县| 广饶县| 石阡县| 民勤县| 德昌县| 大兴区| 南郑县| 大港区| 鹿泉市| 宜宾市| 富宁县| 永康市| 南安市| 宜昌市| 江孜县| 香港 | 齐齐哈尔市| 舒兰市| 习水县| 尼玛县| 沙田区| 渭南市| 宿州市| 应用必备| 安龙县| 滦平县| 竹溪县| 沂水县| 娱乐| 南京市| 扶绥县| 民权县| 海城市| 高碑店市| 洛川县| 闻喜县|