UItableView基本步骤(代码实现中还包含快速创建数组)
来源:互联网 发布:快乐秒赞去授权源码 编辑:程序博客网 时间:2024/05/17 09:10
// ViewController.m// TableView基础#import "ViewController.h"#define kHead "head"@interface ViewController ()<UITableViewDataSource , UITableViewDelegate> //<2>{ NSArray *_allAry;}@end@implementation ViewController- (void)viewDidLoad{ [super viewDidLoad]; UITableView *myTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped]; [self.view addSubview:myTableView]; //必须实现tableview的数据源才能使用tableview <1> myTableView.dataSource = self; myTableView.delegate = self; // NSDictionary *sdDic = @{@"head": @"山东",// @"foot": @"山东欢迎您!",// @"cities" :@[@"烟台",@"济南",@"青岛",@"威海",@"淄博",@"潍坊",@"德州"]// }; _allAry = @[ @{@kHead: @"山东", @"foot": @"山东欢迎您!", @"cities" :@[@"烟台",@"济南",@"青岛",@"威海",@"淄博",@"潍坊",@"德州"] }, @{@kHead: @"北京", @"foot": @"北京欢迎您!", @"cities" :@[@"海淀区",@"石景山区",@"朝阳区",@"东城区",@"西城区",@"昌平区"] }, @{@kHead: @"江苏", @"foot": @"江苏欢迎您!", @"cities" :@[@"南京",@"徐州",@"苏州",@"常州"] }, @{@kHead: @"浙江", @"foot": @"浙江欢迎您!", @"cities" :@[@"杭州",@"宁波",@"义务"] } ];}#pragma mark 3-1. 分几组-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return _allAry.count;}#pragma mark 3-2. 返回每个分区有几行-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [[_allAry[section] objectForKey:@"cities"] count];}#pragma mark 3-3. 每一行显示的内容-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil]; cell.textLabel.text = [_allAry[indexPath.section] objectForKey:@"cities"][indexPath.row]; return cell;}-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ return [_allAry[section] objectForKey:@kHead];}-(NSString*)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{ return [_allAry[section] objectForKey:@"foot"];}-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 70;}#pragma 调整每行的高度-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 60;}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning];}@end
0 0
- UItableView基本步骤(代码实现中还包含快速创建数组)
- 快速排序基本思想以及代码实现
- UI023---代码实现UITableView
- 在android中创建包含对象数组的Parcelable
- 属性动画步骤总结——包含xml实现与java代码实现
- UITableView中实现ComboBox
- IOS 开发之UITableview的基本创建
- 快速创建数组
- 代码实现 UITableView与UITableViewCell
- 代码实现 UITableView与UITableViewCell
- 代码实现 UITableView与UITableViewCell
- 代码实现 UITableView与UITableViewCell
- 创建HttpServlet的基本步骤
- 创建HttpServlet的基本步骤
- 创建ListView的基本步骤
- 创建ListView的基本步骤
- Mysql 数据库创建基本步骤
- WEBPACK 创建基本项目步骤
- 几款iOS开发常用工具
- iOS各类优化方案(一)
- hdu 2159 01背包
- Android编译系统的架构:
- 整理Android项目开发中使用频率很高的小方法
- UItableView基本步骤(代码实现中还包含快速创建数组)
- Java:对象的强、软、弱和虚引用
- select case 用法
- hduoj1060(Leftmost Digit)
- 持续集成与持续交付
- 如何获取span或Label控件中的值?
- 关于tableview的零散代码(一)将buttton放在tableview的footer里
- 4sum问题
- iOS各类优化方案(二)之前整理有借鉴别人的