-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
方法2: 设置UITableView 中, 每个 Section 中有多少个 Cell (确定一个区域能停多少车)
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
方法3: 在每个分组的头部文件位置可以设置任意内容,因为他要的返回值是 UIView,所有的UI类的控件都能创建添加到UIView创建的对象里,再返回UIView的对象
DEMO:
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
// rows 是停车位; cell 是车;
- (void)viewDidLoad {
[super viewDidLoad];
// 风格设置为Plain,当有两个section 的时候中间没有分隔效果,设置为Grouped有分隔效果
UITableView *tv =[[UITableView alloc]initWithFrame:self.view.boundsstyle:UITableViewStyleGrouped];
tv.dataSource=self;
tv.delegate=self;
[self.view addSubview:tv];
// 注册带有标识的tv
[tv registerClass:[UITableViewCell class] forCellReuseIdentifier:@"标识"];
// 返回行数 rows ;确定停车场的停车位数量/如果识多个section那么表示没个section的rows
// 设置 UITableView 中, 每个 Section 中有多少个 Cell (确定一个区域能停多少车)
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 5;
}
// 创建并设置 UITableView 中的 Cell (确定停车"装饰")
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
如果一个ViewDidLoad页面里两个table,那么通过在ViewDidLoad创建table时候给每个table附上tag值
*** 此方法里有两个已知的参数 tableView,indexPath
1、准备初始化 Cell (Cell 的复用机制)
先去可复用 Cell 队列里面找一下, 看看是否有可以复用的标识的 Cell
1 老方法
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"标识"];
if (cell==nil) {
创建一个带有标识的cell
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"标识"];
}
新方法 (之前在viewDidload已经注册过) *****************
//indexPath是方法已知的参数,forIndexPath:indexPath 表示把带有“标识”的cel取出来放在indexPath,具体怎么取得,怎么放得是苹果的.m文件里做的。我们看不到。
转载于:https://www.cnblogs.com/lanyisanqqi/p/5110948.html
