日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

xcode 4.3.2 use storyboard创建TableView

發(fā)布時(shí)間:2023/11/27 生活经验 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 xcode 4.3.2 use storyboard创建TableView 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

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)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。