1、如何建立ui
1.在ViewController中添加TableViewspa
stroyboard或者code添加code
storyboard:直接拖拽并调整好尺寸,添加outletorm
code:1.声明 UItableView *tbv;索引
2.初始化 tbv =[[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];文档
3.显示 [self.view addSubview:tbv];it
2.在ViewController.m中加入<UITableViewDataSource>协议 或io
在其余类中添加此协议table
3.在ViewController.m中使此TableView的数据源为自己 或form
其余类
4.添加
(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView //返回组数 noRequired
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section //返回每组的cell数 Required
(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section //返回每一个组的组名 noRequired
(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath //返回cell Required
(NSArray<NSString *>*)sectionIndexTitlesForTableView:(UITableView*)tableView //在右侧侧显示索引,方便快速查找(电话簿里就有) noRequired
(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index //右侧索引按下时引用
(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section //设置指定section的标题
(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section //设置指定section的脚标题
等方法
2、使用小问题
1.点击按钮后连续切换两次同一个View
在经过storyboard设置segue时,从按钮添加push,同时又在button action中添加了[self performSegueWithIdentifier:@"toTable" sender:nil];这一语句。解决办法就是从前一个view直接push到下一个view,按钮方法保持不变。
2.indexPath相似于一个树状结构,用于tableView时有两层,section和row,方法在文档中写的很清楚。
----
待更新。。。
周二考电磁场与电磁波,明儿得突击24小时了。。
----
后天又是考试,下一次编辑估计就是年后啦