码迷,mamicode.com
首页 > 移动开发 > 详细

IOS学习笔记(三)TableVIew

时间:2015-01-22 00:00:05      阅读:652      评论:0      收藏:0      [点我收藏+]

标签:

如果有需要跟踪NSArray中的内容,需要重写descriptionWithLocal 方法。首先新建一个NSArray 的Category,在新建出来的.m文件中加入下列代码

技术分享

 

- (NSString *)descriptionWithLocal:(id)local 

{

  NSMutableString *string = [NSMutableString string];

  [string appendString:@"("];

  for (id obj in self) {

    [string appendFormat:@"\n\t\"%@\",", obj];

  }

  [string appendString:@"\n)"];

  return string;

}

如此一来,用NSLog显示NSArry中的数据不再是utf-8编码,显示为原来数据。

 

UITableView

需要一个数据源来显示数据


1.需加入数据源协议                                UITableViewDataSource     ;     <

2. 设置表格的组数                              - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView   ;      <      

3.设置每个分组中的行数                       - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section  ;    <

4.设置每个分组中显示的数据内容               - (UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPaht:(NSIndexPath *)indexPath  {

                    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIndentifier:nil];

                    indexPath.section      即为分组名

}  cell即是返回的分组中的数据。                   

5.设置分组的标题            - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSIntger)secton       ;    <

6.设置页脚的标题, 分组底部的子标题        - (NSString *)tableView:(UITableVIew *)tableView titleForFooterInSection:(NSInteger)section     ;    <

7.字典返回所有keys的方法         NSArray *items = [self.cities allKeys];    <   里面数据出来的顺序是乱的

8.将UITableView中的分组分开(即设置style,但style只能在初始化的时候设定)  

                    UITableView *tableView = [[UITableView alloc] initWithFrame: style:(UITableViewStyle)]         ;     <

9.代理方法:                     - (void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndex *)indexPaht   ;   <

 

 

细节决定成败!                     

IOS学习笔记(三)TableVIew

标签:

原文地址:http://www.cnblogs.com/fsliu/p/4240211.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!