您的位置:首页 > 其它

Table View 学习

2015-06-19 16:58 323 查看
源码下载

一直在考虑这个拖在那里,在看老的视频的时候直接拖在file's owner 但是在新故事版中不存了,所以一直纠结中,无论拖在那里都是错误的。



通过代码写仿佛也错误。



主要实现的几个方法如下:

// 用于返回table view有多少行。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

return [myar1 count];

}

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:

// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)

//用于显示有行,这里有一个性能问题,就是当拖动的时候显示性能问题。要新创建一个cell。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

static NSString *TableSampleIdentifier = @"cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:

TableSampleIdentifier];

if (cell == nil) {

cell = [[UITableViewCell alloc]

initWithStyle:UITableViewCellStyleDefault

reuseIdentifier:TableSampleIdentifier];

}

NSUInteger row = [indexPath row];

cell.textLabel.text = [myar1 objectAtIndex:row];

UIImage *image = [UIImage imageNamed:[myar2 objectAtIndex:
row]];

cell.imageView.image =image;

return cell;

}

显示效果:



显示组用这个:



// 选择相应的行用

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

if([indexPath section]==0){

//直接有 section用section 选择

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

//return [myar1 count];

if (section==0) {

//分段标题

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{

if(section==0){

return @"test1";

}else{

return @"test3";

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: