今天刘国斌老师讲了oc语言里非常重要也是很常用的UI控件UITableView,一天的学习节奏很紧凑,上午听课有些吃力,中午利用休息时间把知识内容友写了几遍,下午的课听的效果很好,加上老师通俗易懂的教课方式,对于UITableView的学习暂时有了出入的掌握。
晚上学习完即使把UITableView知识点整理了出来:
方法1:
创建并设置 UITableView 中的 Cell (确定停车"装饰")
-(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