xcode 4.3.2 use storyboard创建TableView
xcode 4.3.2 use storyboard 使用TableView,顯示一個(gè)顏色列表,表格包括一張圖片,一個(gè)文本,一行副文本。
?
TableView 呈現(xiàn)列表格式的數(shù)據(jù),每一行是一個(gè)UITableViewCell對(duì)象,每個(gè)UITableViewCell可以顯示文本標(biāo)簽(為textLabel),字幕(detailedTextLabel)和圖像(ImageView)。
每一個(gè)TableView,需要有與之相關(guān)的委托(delegate)和一個(gè)數(shù)據(jù)源(DataSource)。
委托實(shí)現(xiàn)UITableViewDelegate的協(xié)議,并提供額外的控制的外觀和功能表視圖,包括檢測(cè)用戶觸摸時(shí)特定的行,自定義行高和縮進(jìn),并實(shí)施行刪除和編輯功能。
數(shù)據(jù)源,實(shí)現(xiàn)UITableViewDataSource協(xié)議,基本上包含方法定義標(biāo)題信息,要顯示多少行數(shù)據(jù),如何將數(shù)據(jù)劃分成不同的部分。
?
1,新建Single View Application ,use storyboard。?
2,storyboard中ViewController中,拖入一個(gè)Table View ,設(shè)置TableView 的Outlets的dataSource和delegate 連線到View Controller
3,ViewController.h?
@interface ViewController : UIViewController<UITableViewDelegate,UITableViewDataSource>{NSArray *colorName;// 數(shù)據(jù)源 } @property (nonatomic,retain) NSArray *colorName;
4,ViewController.m
@synthesize colorName; - (void)viewDidLoad {[super viewDidLoad];// 初始化加載視圖時(shí)的一些數(shù)據(jù)colorName = [[NSArray alloc] initWithObjects:@"Red",@"Green",@"Yellow",@"Blue",@"White",@"Black", nil]; } /**獲取TableView顯示的行數(shù)*/ -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{return [colorName count]; } /**定義Cell外觀*/ -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{static NSString *CellIdentifier = @"Cell";UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];if(cell == nil){cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];}//設(shè)置圖片,PolyStar.png是項(xiàng)目資源中的圖片名UIImage *image = [UIImage imageNamed:@"PolyStar.png"];cell.imageView.image = image;//設(shè)置文字NSString *color = [colorName objectAtIndex:[indexPath row]];cell.textLabel.text = color;//設(shè)置詳細(xì)介紹NSString *desc = [NSString stringWithFormat:@"關(guān)于顏色"];desc = [desc stringByAppendingFormat:color];cell.detailTextLabel.text = desc;return cell; }
OK.
學(xué)習(xí)ing ...
?
轉(zhuǎn)載于:https://www.cnblogs.com/tqspring/archive/2012/05/31/2528016.html
總結(jié)
以上是生活随笔為你收集整理的xcode 4.3.2 use storyboard创建TableView的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: VC串口通信编程-2
- 下一篇: 女方患有先天性脑部血管畸形,也就是血管瘤