IOS學習之——表視圖3 自訂儲存格

來源:互聯網
上載者:User

標籤:自訂儲存格   uitableviewcell   ios   

寫在前面

今天看新聞,科比肩部撕裂,可能會提前退役,這個頑固的男人,終於要落幕了,雖然我不是他的球迷,也是心生敬仰,今天的主題就以科比為素材,向這位人生的鬥士致敬。

前面我們講到了tableview的單元格的系統內建的image label,用起來很方便,可是畢竟限制很多,這一篇將會講到一個神奇的東西——自訂單元格,由你控制單元格顯示的內容,位置,形式。如,我們要製作一個球星列表,需要四項資訊:頭像+姓名+年齡+性別


設定介面
拖控制項,如設定單元格高度,這裡要講一下高度有兩個:
  1. 設定tableview  的row  高度為:180  這個高度是tableview的行高,就是不管你要多大的cell,螢幕上都只能佔一行的高度……
  2. 設定cell高度,——這個是cell本身的高度
在介面設定複用:
添加自訂控制項類
添加自訂控制項類:繼承tableviewcell
<span style="font-size:14px;">#import <UIKit/UIKit.h>@interface CustomTableViewCell : UITableViewCell@property (weak, nonatomic) IBOutlet UIImageView *image;@property (weak, nonatomic) IBOutlet UILabel *name;@property (weak, nonatomic) IBOutlet UILabel *age;@property (weak, nonatomic) IBOutlet UILabel *phone;@end</span>
選擇cell,讓關聯自訂類和storyboard
在tableview裡面對自訂的類進行操作即可
#import "CustomTableViewController.h"#import "CustomTableViewCell.h"@interface CustomTableViewController ()<UITableViewDataSource>@end@implementation CustomTableViewController- (void)viewDidLoad {    [super viewDidLoad];}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}#pragma mark - Table view data source- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {    // Return the number of sections.    return 1;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {    // Return the number of rows in the section.    return 1;}-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    static NSString *[email protected]"Cell";    CustomTableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];        [email protected]"科比";    [email protected]"37";    [email protected]"男";    cell.image.image=[UIImage imageNamed:@"Kobe.png"];    return cell;}


相關代碼
http://git.oschina.net/zhengaoxing/table1-type

歡迎轉載,轉載請註明出處

本文地址:http://blog.csdn.net/zhenggaoxing/article/details/43086621

43086621



IOS學習之——表視圖3 自訂儲存格

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.