目录:

一、tableview的编辑模式-增删改查

二、不使用继承创建tableview

三、accessoryView辅助视图

回到顶部

一、tableview的编辑模式-增删改查

[1-contact-edit]

增:

1对数据模型增加数据

self.contacts addObject:

2对tableview增加行

self.tableView insertRowsAtIndexPaths

删改查:

tableview进入编辑模式

1如何设置编辑模式UITableView.editing

2能干什么:添加、删除、移动

这些都是对cell进行的操作

3进入编辑模式的快捷方式是把viewDidLoad中的self.editButtonItem显示出来,一旦按了按钮,tableview就会进入编辑模式,默认情况下是删除模式

4如果需要达到删除的效果需要进行两问一响应,两个问题可以不回答,但必须有响应

两问:

1)第一问哪些行可以进行编辑,哪些不能

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

2)第二问哪些行可以进行删除,哪些行可以进行插入

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

3)一响应当用户选择了行进行删除或插入,如何处理

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

回到顶部

二、不使用继承创建tableview

[2-tableView]

并提供三问一响应的链接dataSource和delegate到要提供数据的viewcontroller,这个viewcontroller要遵守detaSource这个协议

- (void)viewDidLoad
{
    [super viewDidLoad];
    UITableView *tableView = [[UITableView alloc] init];
    tableView.frame = CGRectMake(160, 42, 122, 322);
    tableView.dataSource = self;
    [self.view addSubview:tableView];
    // Do any additional setup after loading the view, typically from a nib.
}

静态的tableview

分区和行数都是固定的,如果用代码实现都是直接写死的。

回到顶部

三、accessoryView辅助视图

是tableview中cell的子试图中的一个,

有哪些类型:iOS6之前有4种iOS7增加了一种,

干什么用呢?触发高级事件

//返回cell数据
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    cell.textLabel.text = @"ddd";
    //设置辅助视图  也就是cell右边的那个视图
    
    if (indexPath.row == 0) {
        //开关
        cell.accessoryView = [[UISwitch alloc] init];
    }else{
        cell.accessoryType = UITableViewCellAccessoryDetailButton;
    }
    return cell;
}
//点击cell之后调用的方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"+++");
}
//点击辅助视图调用的方法
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"---");
}

作业:

1. 在一个界面上有两个TableView, 其中一个显示城市列表,如:北京,上海, 广州..,另一个显示用户选中的那个城市的行政区列表,如: 东城,西城,…, 当用户选中了某个行政区,界面上的一个TextView就显示此行政区的简介。

数据模型自己设计。

2. TMusic的设置界面,根据给的资源包高仿QQ音乐的设置界面。

补充:

UI控件用weak,NSString用copy,其他对象一般用strong

tableviewcell的高度有一个代理方法来调

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

字符串追加

cell.detailTextLabel.text = [[contact.phoneName stringByAppendingString:@"\t"] stringByAppendingString:contact.iphone];

//更新界面

NSIndexPath *indexPath = [NSIndexPath indexPathForItem:self.contacts.count -1 inSection:0];

[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

07-UIKit(tableview的编辑模式、accessoryView)的更多相关文章

  1. iOS UIKit:TableView之编辑模式(3)

    一般table view有编辑模式和正常模式,当table view进入编辑模式时,会在row的左边显示编辑和重排控件,如图 42所示的编辑模式时的控件布局:左边的editing control有表 ...

  2. ios之UITableViewController(二) tableView的编辑模式

    tableView的编辑模式 表视图可以进入编辑模式,当进入编辑模式就可以进行删除.插入.移动单元等操作 效果图: 让表视图进入编辑模式,进入编辑模式的方法有两种,一种是使用导航栏的edit 按钮,另 ...

  3. IOS第13天(3,私人通讯录,登陆状态数据存储,数据缓存, cell的滑动删除,进入编辑模式,单个位置刷新 )

    *****联系人的界面的优化 HMContactsTableViewController.m #import "HMContactsTableViewController.h" # ...

  4. UITableView编辑模式大全解

    1.UITableView 的编辑模式 进入编辑模式 代码体现 // 设置 editing 属性 tableView?.editing = true // 这个设置的时候是有动画效果的 tableVi ...

  5. IOS开发学习笔记032-UITableView 的编辑模式

    UITableView 的三种编辑模式 1.删除 2.排序 3.添加 进入编辑模式,需要设置一个参数 - (IBAction)remove:(UIBarButtonItem *)sender { NS ...

  6. iOS开发——UI进阶篇(四)tableView的全局刷新,局部刷新,左滑操作,左滑出现更多按钮,进入编辑模式,批量删除,自定义批量删除

    首先创建项目,在storyboard如下布局控件,设置好约束 然后创建cell模型类XMGWineCell数据模型类XMGWine创建UITableView,设置数据源协议,实现数据源方法懒加载数据这 ...

  7. IOS第七天(6:UiTableView编辑模式, 拖动位置 ,滑动删除)

    **********UiTableView编辑模式, 拖动位置 ,滑动删除 #import "HMViewController.h" @interface HMViewContro ...

  8. UITableView的编辑模式

    UITableView可以分普通模式和Editing模式两种,这里我们着重讨论Editing模式,Editing模式中又分三种操作:Insert.Delete. Reallocted.Insert和D ...

  9. UITableView 编辑模式(增加-删除-移动---自定义左滑 title)

    - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typica ...

随机推荐

  1. HYSBZ1588 营业额统计【Splay】

    转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4366582.html   ---by 墨染之樱花 [题目链接]http://www.lydsy ...

  2. US/OS2之任务同步与通信

    嵌入式系统中的各个任务都是以并发的方式来运行的,并为同一个大的任务服务,它们不可避免地要共同使用一些共享资源,并且在处理一些需要多个任务共同协作来完成的工作时,还需要相互的支持和限制.因此,对于一个完 ...

  3. U盘安装Win7系统教程

    U盘安装系统教程: http://wiki.jd.com/knowledge/6699.html

  4. 【JAVA】使用Eclipse依赖生成jar包时,避免最外层同时生成资源文件的配置。

    使用Eclipse依赖生成jar包时,如果做配置,生成的jar包文件会全部生成在外面,这并不是我们需要的,下面我们一起来修改下配置,使生成的jar包符合我们的需求吧. 1.如果不做任何配置生成的jar ...

  5. OCP-1Z0-053-V13.02-712新题

       Why does the number of blocks for the table remain the sale after the shrink operation? A.Because ...

  6. PHP数组与对象之间用递归转换

    2 3 4 5 6 7 8  function object_to_array($e) {      $_arr = is_object($e) ? get_object_vars($e) : $e; ...

  7. Judge loop in directed graph

    1 深度优先方法 首先需要更改矩阵初始化函数init_graph() 然后我们需要初始化vist标记数组 深度优先访问图,然后根据是否存在back edge判断是否存在环路 算法如下: #includ ...

  8. virtual host

    <VirtualHost *:80>     ServerAdmin webmaster@dummy-host.php100.com     DocumentRoot "G:/w ...

  9. POJ 1472 Coins (多重背包+滚动数组)

    Coins Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 25827 Accepted: 8741 Description Pe ...

  10. 误mlogc.c:32:23: error: curl/curl.h: No such file or directory

    出现以下错误: mlogc.c:32:23: error: curl/curl.h: No such file or directory mlogc.c:1091: error: expected ' ...