- 2 2 4
// UITableView有两种风格,UITableViewStylePlain,UITableViewStyleGrouped
// UITableView有两个代理,<UITableViewDataSource,UITableViewDelegate>,table.dataSource = self;table.delegate = self;//两个代理
// UITableView有四个cell风格,UITableViewCellStyleDefault,UITableViewCellStyleSubtitle,UITableViewCellStyleValue1,UITableViewCellStyleValue2
- UITableViewDataSource的方法重点,@required
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;{
return self.arr.count;
}
//每一行都要执行一遍,UITableViewDataSource的方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;{
static NSString *identity = @"cell";
UITableViewCell *cell;
if(cell==nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identity];
}
//UITableViewCellStyleDefault 这种形式是一张图,一行文字,也可自行减少
//如果有详情的话,换成UITableViewCellStyleSubtitle
Person *p = self.arr[indexPath.row];
cell.textLabel.text = p.data;
cell.detailTextLabel.text = p.detail;
cell.imageView.image = [UIImage imageNamed:p.imagename];
NSLog(@"row==%ld,cell==%p",indexPath.row,cell );
cell.accessoryType = UITableViewCellAccessoryCheckmark;//属性为右边对号,感叹号等样式
return cell;
}
3.上拉,下拉,刷新(第三方)方法
//开启刷新状态
[self setupRefresh];
//开始刷新自定义方法
- (void)setupRefresh
{
//下拉刷新
[self.table addHeaderWithTarget:self action:@selector(headerRereshing) dateKey:@"table"];
[self.table headerBeginRefreshing];
// 上拉加载更多(进入刷新状态就会调用self的footerRereshing)
[self.table addFooterWithTarget:self action:@selector(footerRereshing)];
//一些设置
// 设置文字(也可以不设置,默认的文字在MJRefreshConst中修改)
self.table.headerPullToRefreshText = @"下拉可以刷新了";
self.table.headerReleaseToRefreshText = @"松开马上刷新了";
self.table.headerRefreshingText = @"刷新中。。。";
self.table.footerPullToRefreshText = @"上拉可以加载更多数据了";
self.table.footerReleaseToRefreshText = @"松开马上加载更多数据了";
self.table.footerRefreshingText = @"加载中。。。";
}
//下拉刷新
- (void)headerRereshing
{
//一般这些个里边是网络请求,然后会有延迟,不会像现在刷新这么快
[self performSelector:@selector(request) withObject:nil afterDelay:5];
}
- (void)request{
// 添加假数据
//[self.arr insertObject:@"这是刷新的数据" atIndex:0];
[self.table reloadData];
//结束刷新
[self.table headerEndRefreshing];
}
//上拉加载
- (void)footerRereshing
{
//这个一般是提取缓存的数据
// 添加假数据
//[self.arr insertObject:@"这是加载以前的数据" atIndex:[self.arr count]];
[self.table reloadData];
//结束刷新
[self.table footerEndRefreshing];
}
网友评论