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. em px 简单换算

    大部分的网页设计者在CSS代码编写中总是先对整体定义字体尺寸,中文情况下一般为12px,而其实这样以来在通过IE顶部菜单中的“察看-文字大小”设置已无任何 作用.对字体感觉太小的浏览者而言无疑是种很不 ...

  2. php设计模式 1单例模式

    之前很长时间之前就学习过设计模式,但是因为在实践中很少应用,所以忽略了,但现在却意识到设计模式很重要的,程序设计简介高效冗余性代码少. 今天开始把前几天学习的几个设计模式整理一下,首先当然是单例模式. ...

  3. 《python基础教程》笔记之 列表

    list函数 list函数将其他类型的序列转换为列表,如 >>> list("hello world")['h', 'e', 'l', 'l', 'o', ' ' ...

  4. 关于Cococs中的CCActionEase

    尊重作者劳动,转载时请标明文章出处.作者:Bugs Bunny地址:http://www.cnblogs.com/cocos2d-x/archive/2012/03/13/2393898.html 本 ...

  5. Java学习笔记--堆、栈、常量池

    参考资料:http://blog.csdn.net/miraclestar/article/details/6039743 Java内存区域模型主要分为4部分 1.方法区 2.本地方法栈 3.栈 4. ...

  6. android中如何处理cookie

    Managing Cookies HttpClient provides cookie management features that can be particularly useful to t ...

  7. uva 10007 Count the Trees

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  8. Gridview中的数据导出到excel中

    protected void btnExport_Click(object sender, EventArgs e)    {                   //导出全部数据,取消分页      ...

  9. QQ登录-第三方SDK的接入总结(搜索 qq互联)

    由于项目的需要,使用了[QQ登录]SDK 的相关功能!   1.集成[QQ登录]SDK   [QQ登录]SDK下载地址: http://wiki.open.qq.com/wiki/website/SD ...

  10. BZOJ3398: [Usaco2009 Feb]Bullcow 牡牛和牝牛

    3398: [Usaco2009 Feb]Bullcow 牡牛和牝牛 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 30  Solved: 17[Sub ...