UITableView:特殊的滚动视图,横向固定,可以在纵向上滚动,自动计算contentSize

创建tableView,初始化时指定样式,默认是plain

UITableView *_tableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 20, 375, 600) style:UITableViewStylePlain];

与数据源相关的方法都在dataSource的协议方法中

_tableView.dataSource=self;

与ui相关的方法都在delegate的协议方法中

_tableView.delegate=self;

设置每组的数据行数

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

显示每行数据时都会调用此方法,设置每行数据的显示样式(单元格内容样式),显示单元格,采用了可重用机制,当向上拖动tableView显示新的数据时,(原来的单元格不可见,将其加入到可重用队列中,)每次显示单元格信息时先从可重用队列中取出可重用的单元格,如果没有再自己创建

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

设置是否自动调整视图位置

self.automaticallyAdjustsScrollViewInsets=NO;

根据标识符在可重用队列中取出单元格

UITableViewCell* cell=[tableView dequeueReusableCellWithIdentifier:identifier];

设置单元格右侧的箭头样式

cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;

UITableViewCellAccessoryDisclosureIndicator;//右箭头

UITableViewCellAccessoryDetailButton;//问号

UITableViewCellAccessoryDetailDisclosureButton;//问号加右箭头

UITableViewCellAccessoryCheckmark;//对号

UITableViewCellAccessoryNone;//空

图片,一般在左侧显示

cell.imageView.image=[UIImage imageNamed:@"0.png"];

详细信息

cell.detailTextLabel.text=@"detail";

设置每行的行高:默认是44

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;

当选择某行数据时调用此协议方法

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;

当取消选择某行数据时,

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath;

每个UIViewController都有一个editButtonItem属性,当向它发送editButtonItem消息时会自动创建一个名为edit的UIBarButtonItem对象,自动设定目标-action。自动调用setEditing:animated:方法

self.navigationItem.leftBarButtonItem=self.editButtonItem;

单击导航栏上的edit项时执行此协议方法

-(void)setEditing:(BOOL)editing animated:(BOOL)animated;

设置表视图与edit一样是否处于编辑状态

[_tableView setEditing:editing animated:animated];

section是表视图中每组的编号,从0开始,设置每行的数据行数

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

设置tableView的分组数

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;

//设置每组的标题,section是组的编号

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;

//对tableView编辑(删除、插入)的操作

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;

1、删除数据源中的数据(删除第indexPath.section组中第indexPath.row行的数据

[_dataArray[indexPath.section] removeObjectAtIndex:indexPath.row];

2、刷新表视图,第1个参数是删除的行的indexPath组数,第2个参数是动画效果样式

[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];

刷新所有的数据

[tableView reloadData];

tableView的编辑状态有UITableViewCellEditingStyleDelete, UITableViewCellEditingStyleInsert, UITableViewCellEditingStyleNone

UI控件之UITableView的基本属性的更多相关文章

  1. UI控件之UITableView的协议方法

    <UITableViewDataSource,UITableViewDelegate> //设置表视图的编辑状态 -(void)setEditing:(BOOL)editing anima ...

  2. AppleWatch___学习笔记(二)UI布局和UI控件

    1.UI布局 直接开发,你会发现Apple Watch并不支持AutoLayout,WatchKit里有个类叫做WKInterfaceGroup,乍一看像是UIView,但是这货其实是用来布局的.从 ...

  3. ios 中的UI控件学习总结(1)

    UIKit框架提供了非常多功能强大又易用的UI控件 下面列举一些在开发中可能用得上的UI控件 UIButton 按钮 UILabel 文本标签 UITextField 文本输入框 UIImageVie ...

  4. 面试题汇总--数据储存/应用程序/UI控件/客户端的安全性与框架处理。。。

    一 数据储存  1.如果后期需要增加数据库中的字段怎么实现,如果不使用 CoreData 呢?编写 SQL 语句来操作原来表中的字段1)增加表字段ALTER TABLE 表名 ADD COLUMN 字 ...

  5. UI控件概述

    常见UI控件 UIKit框架提供了非常多功能强大又易用的UI控件,以便于开发者打造出各式各样的App 以下列举一些在开发中常见的UI控件(稍后补上图片示例) 1.UILabel– 文本标签:作用是显示 ...

  6. iOS-UI控件之UITableView(一)

    UITableView 介绍 UITableView 是用来用列表的形式显示数据的UI控件 举例 QQ好友列表 通讯录 iPhone设置列表 tableView 常见属性 // 设置每一行cell的高 ...

  7. 常用的UI控件

    关于本文:作为一名iOS软件工程师,熟练规范的使用常用的UI控件是必备的基础技能. 指示器(UIActivityIndicatorView)----转动的等待小菊花 提醒对话框(UIAlertView ...

  8. ANDROID L——Material Design详解(UI控件)

    转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! Android L: Google已经确认Android L就是Android Lolli ...

  9. WinForm/Silverlight多线程编程中如何更新UI控件的值

    单线程的winfom程序中,设置一个控件的值是很easy的事情,直接 this.TextBox1.value = "Hello World!";就搞定了,但是如果在一个新线程中这么 ...

随机推荐

  1. uva753 A Plug for UNIX 网络流最大流

    C - A Plug for UNIX    You are in charge of setting up the press room for the inaugural meeting of t ...

  2. win10实现移动热点共享WIFI

    电脑有线上网有WIFI网卡,想共享WIFI给手机还在为下载猎豹WIFI.360WIFI.WIFI共享精灵?担心密码泄露?担心网络安全?现在一切都不用烦恼.windows10系统自带热点共享 工具/原料 ...

  3. 【Python + ATX基于uiautomator2】之编写unittest自动化测试脚本

    不说废话上代码: #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2018/08/31 09:43 # @Author : zc # @ ...

  4. [已解决]windows下python3.x与python2.7共存版本pip使用报错问题

    > 由于最近要更新插件,突然发现没法使用pip来安装升级插件,查了一圈才找到解决办法,特记录在此,便于其它人查询. 报错信息如下: Fatal error in launcher: Unable ...

  5. OpenCV中Camshitf算法学习(补充)

    结合OpenCV中Camshitf算法学习,做一些简单的补充,包括: 实现全自动跟随的一种方法 参考opencv中的相关demo,可以截取目标物体的图片,由此预先计算出其色彩投影图,用于实际的目标跟随 ...

  6. Package java.sql

    Provides the API for accessing and processing data stored in a data source (usually a relational dat ...

  7. IDEA15入门常用设置

    打开IDEA设置的快捷键:Ctrl + Alt + S 打开选中的项目属性快捷键:Shift + Ctrl + Alt + S 1.IDEA默认不会使用我们独立安装的Maven配置,需要手动设置,并且 ...

  8. node.js 入门

    什么是Node.js?还服务器端javascript?对于这个概念我在这篇文章不做解释,可以自己去搜索了解下,服务器端js不是新技术,只是最近的node.js的火爆让他爆发了,我会在以后的文章里解释什 ...

  9. 项模板选择器属性(ItemTemplateSelector属性)和样式选择器(ItemContainerStyleSelector)

    3.4.5 共享尺寸组 样式选择器: 或者========================================

  10. Apache的下载以及安装

    前言:生活,生下来,活下去 第一步:在浏览器的搜索栏输入:apache下载:显示如下,单机进入Apache的官网