TableView基本使用

基本步奏

  • 1设置数据源
    self.tableview.dataSource = self;
  • 2遵守协议
@interface ViewController () <UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableview;
  • 3实现方法

    有几组

    每组有几行

    每行设置什麽 内置了那些控件,自己点击command查找

/**

* 不是必须实现的方法

*

* @param tableView

*

* @return tabeleview多少分组

*/

“`objc

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

return 3;

}

/**
* 必须实现的方法
*
* @param tableView
* @param section
*
* @return 告诉tableview每个分组有多少行
*/
```objc
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0) {
return 2;
}
else if (section == 1)
{
return 3;
}
else
{
return 4;
}
}

/**

* 对分组每行的内容进行设置

*

* @param tableView

* @param indexPath

*

* @return (UITableViewCell *)

*/

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell = [[UITableViewCell alloc] init]; if (indexPath.row == 0) {
cell.textLabel.text = @"通用";
}
else if(indexPath.row == 1)
{
cell.textLabel.text = @"隐私";
}
else if (indexPath.row == 2)
{
cell.textLabel.text = @"必须";
}
else
{
cell.textLabel.text = @"得更新";
} return cell;
}

效果图:

出现的问题图:





TableView基本使用的更多相关文章

  1. iOS有关横向TableView的东西

    之前看到Apple store里面有横向的tableview,当然也有可能是collectionview啦. 尤其是项目中只有一条那么需要横向滑动的东西,就没有必要使用庞大的collectionvie ...

  2. tableView显示第一个cell有偏移问题

    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 0 ...

  3. [tableView reloadData] 和 runloop

    需要[tableView reloadData]后需要立即获取tableview的cell.高度,或者需要滚动tableview,那么,直接在reloadData后执行代码是会有问题的. 断点调试感觉 ...

  4. 【代码笔记】iOS-一个tableView,两个section

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...

  5. 【Swift】Alamofile网络请求数据更新TableView的坑

    写这篇BLOG前,有些话不得不提一下,就仅当发发恼骚吧... 今天下午为了一个Alamofire取得数据而更新TableView的问题,查了一下午的百度(360也是见鬼的一样),竟然没有一个简单明了的 ...

  6. TableView 滑动收起键盘

    self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag; 拖拽tableView就会收起键盘

  7. 关于TableView上有一段留白的解决方法

    当cell的类型是plaint类型时 直接设置self.automaticallyAdjustsScrollViewInsets=NO; 还有要注意检查你自己设置的frame是否正确     当cel ...

  8. iOS监听tableView组头切换事件

    - (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSIntege ...

  9. 【原】iOS学习之tableView的常见BUG

    1.TableView头视图不随视图移动,头视图出现错位 错误原因:tableView的 UITableViewStyle 没有明确的声明 解决方法:在tableView声明的时候明确为 UITabl ...

  10. 两种让tableview返回顶部的方法

    1. [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:_currentRow inSection:0] animat ...

随机推荐

  1. mysql 5.5 升级到 mysql 5.6

    目前MySQL数据库软件升级到5..26版本,主要有两种方法.一种是停机升级,即在现有环境下先停止数据库,然后升级数据库软件版本和数据库版本:另外一种是采用不停机的主从升级(master--slave ...

  2. jquery在不同浏览器获取文件路径出现问题!

    <input type="file" name="file" id="file1" src=""/> < ...

  3. (转)C#.NET使用TTS引擎实现文语转换

    (转)C#.NET使用TTS引擎实现文语转换 本文讲述使用微软TTS5.1语音引擎(中文)实现文本阅读和音频输出为WAV完美解决方案. 网上很多文章说的是要安装SAPI.51 SDK,而这个东西有好几 ...

  4. tomcat可以访问到软链接设置

    tomcat/conf/context.xml设置<Context allowLinking="true"> 就可以啦.

  5. css3 animation 动画属性简介

    animation 动画属性介绍 animation 属性是一个简写属性,用于设置动画属性: 1. animation-name----规定需要绑定到选择器的 keyframe 名称. 语法:anim ...

  6. smarty练习:考试系统

    考试系统 (0607) 做一个类似于驾校考试的系统,可以选择要考试试题类型,选好后进入考试页面 使用的数据库表格:timu(题目)表,xuanxiang(选项)表,shiti(试题)表,shititi ...

  7. 按钮控件Button

    钮窗口(控件)在MFC中使用CButton表示,CButton包含了三种样式的按钮,Push Button,Check Box,Radio Box.所以在利用CButton对象生成按钮窗口时需要指明按 ...

  8. CFont 字体类

    CFont 字体类 初始化函数 CreateFontIndirect 初始化一个由LOGFONT结构给出其特征的CFont对象 CreateFont 初始化用指定特性定义的CFont对象 Create ...

  9. openwrt上wifi探针的实现

    openwrt上wifi探针的实现 探针是通过wifi搜集经过这个AP范围的手机的mac地址,没有什么深刻的东西,知乎上关于这个东西讨论的很多,有人觉得很有用,可以做很多增值的应用,有人觉得没啥用,不 ...

  10. 自动删除n天前日志

    自动删除n天前日志 linux 是一个很能自动产生文件的系统,日志.邮件.备份等.虽然现在硬盘廉价,我们可以有很多硬盘空间供这些文件浪费,让系统定时清理一些不需要的文件很有一种 爽快的事情.不用你去每 ...