.h中实现两个代理:
Controller : UITableViewController<UITableViewDataSource,UITableViewDelegate>
.m中实现代理中的方法:
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return [self.singers count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
return [self.singerSex objectAtIndex:section] ;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [[self.singers objectAtIndex:section] count] ;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
if(cell == nil){
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSInteger section = [indexPath section];
NSInteger row = [indexPath row];
cell.textLabel.text = [[self.singers objectAtIndex:section] objectAtIndex:row];
return cell;
}
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger section = [indexPath section];
NSInteger row = [indexPath row];
//[self performSegueWithIdentifier:[[self.singers objectAtIndex:section] objectAtIndex:row] sender:nil];
[self performSegueWithIdentifier:@"张学友" sender:[[self.singers objectAtIndex:section] objectAtIndex:row]];
}
当然也可以自定义TableViewCell,在
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
中加载自己的Cell。。。
分享到:
相关推荐
iphone UITableView异步加载图片
iphone UITableView划动删除的实现
UITableView是iPhone中比较常用的,用的比较多的控件, 本例中说明iPhone UITableView的使用方法实例。 该实列中是手动增加UITableViewDataSource和UITableViewDelegate协议来实现的。
iphone UITableView中使用combobox的实例,实现简单方便,但蛮好用的。
iphone uitableview图片延迟加载实例,一个官方例子,自己研究的时候加入了详细的注释,传上来方便自己以后使用。
UITableView 简单例子,显示两个表区域,然后点击每行弹出一个提示框,有代码注释
UITableView 比UIButton等控件比较难以掌握,特别整理了一些核心细节和例子。供大家参考
iPhone UITableView在UITableViewCell中具有自动布局功能以创建动态高度 这段代码来自我的视频教程,该视频教程介绍了如何在iOS 7中为UITableViewCell对象设置自动布局。 有一些陷阱(很多)可以使事情正常进行。 ...
这是iPhone之UITableView入门的示例程序,具体参考: http://blog.csdn.net/htttw/article/details/7875462
iphone 关于UITableView的排序,搜索、使用Interface Builder创建等iphone 关于UITableView的排序,搜索、使用Interface Builder创建等
里面有很多uitableview和uinavigation等控件用法
【iphone应用开发】iphone应用开发之六:UITableView的详细讲解(一)
android listview 圆角的实现方案,模仿Iphone的UITableView 对应的工程
实现tableview的圆角及阴影效果,内有图片展示。
这是iPhone开发之UITableView入门2示例程序,具体参考: http://blog.csdn.net/ht916/article/details/7897486
这个程序是在iPhone3.1.3的模拟器测试通过的,如果大家需要定制UIAlertView的Table请下载这个程序,有很好的参考价值
UITableView教材 IPHONE IPAD
iphone中的基础控件UITableView,适合初学者,主要学习UITableView的常用属性设置、自定义分区标题、cell显示定义、索引列显示、索引列点击事件等。 通讯录按照首字母分区显示,右边显示索引列(A、B、C、D……X、Y...
iphone中的基础控件UITableView的多行编辑控制,适合初学者,主要学习UITableView进行多行编辑的控制,ios5.0以上,SDK 6.0以上版本才可以使用table中选中多行事件。
UITableView 详细讲解