日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

xcode 4.3.2 use storyboard创建TableView

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

xcode 4.3.2 use storyboard 使用TableView,顯示一個顏色列表,表格包括一張圖片,一個文本,一行副文本。

?

TableView 呈現(xiàn)列表格式的數(shù)據(jù),每一行是一個UITableViewCell對象,每個UITableViewCell可以顯示文本標簽(為textLabel),字幕(detailedTextLabel)和圖像(ImageView)。

每一個TableView,需要有與之相關的委托(delegate)和一個數(shù)據(jù)源(DataSource)。

委托實現(xiàn)UITableViewDelegate的協(xié)議,并提供額外的控制的外觀和功能表視圖,包括檢測用戶觸摸時特定的行,自定義行高和縮進,并實施行刪除和編輯功能。

數(shù)據(jù)源,實現(xiàn)UITableViewDataSource協(xié)議,基本上包含方法定義標題信息,要顯示多少行數(shù)據(jù),如何將數(shù)據(jù)劃分成不同的部分。

?

1,新建Single View Application ,use storyboard。?

2,storyboard中ViewController中,拖入一個Table View ,設置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ù)據(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];}//設置圖片,PolyStar.png是項目資源中的圖片名UIImage *image = [UIImage imageNamed:@"PolyStar.png"];cell.imageView.image = image;//設置文字NSString *color = [colorName objectAtIndex:[indexPath row]];cell.textLabel.text = color;//設置詳細介紹NSString *desc = [NSString stringWithFormat:@"關于顏色"];desc = [desc stringByAppendingFormat:color];cell.detailTextLabel.text = desc;return cell;
}

OK.

學習ing ...

?

轉載于:https://www.cnblogs.com/tqspring/archive/2012/05/31/2528016.html

總結

以上是生活随笔為你收集整理的xcode 4.3.2 use storyboard创建TableView的全部內容,希望文章能夠幫你解決所遇到的問題。

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