• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
MJCIOS
博客园    首页    新随笔    联系   管理    订阅  订阅

IOS开发UITableView --UITableView

UITableView的两种样式
UITableViewStylePlain 不分组显示
UITableViewStyleGrouped 分组显示   
 

UITableViewDataSource  //数据源协议

两个必需实现的方法
//一组有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
//每一行显示什么内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
   
    // 设置分隔线颜色
    self.tableView.separatorColor = [UIColor colorWithRed:35/255.0 green:136/255.0 blue:255/255.0 alpha:119/255.0];
   
    // 设置分隔线style
//    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
   
    // tableHeaderView广告位
    self.tableView.tableHeaderView = [[UISwitch alloc] init];
    // 加载更多
    self.tableView.tableFooterView = [UIButton buttonWithType:UIButtonTypeContactAdd];
 
 
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{    // 1.定义一个cell的标识

      static NSString *ID = @"mjcell";

    // 2.从缓存池中取出cell

      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];

    // 3.如果缓存池中没有cell

      if (cell == nil) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];

    }

    // 4.设置cell的属性...

 
       return cell;
 
 
点击每行单元格中的cell显示什么内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
知识慢慢积累,刚开始会感觉好累,时间长了,积累知识多了,以后的工作也会轻松很多....
posted @ 2016-05-09 18:33  MJC(IOS)  阅读(161)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3