OC笔记 - tableView的编辑模式、UITabBarController(2015.3.20)

来源:互联网 发布:泡富婆的软件 编辑:程序博客网 时间:2024/05/02 12:50

1.tableView的编辑模式

// 只在在tableview的编辑模式下才有添加

// 只要实现该方法, 手指在cell上面滑动的时候就自动实现了删除按钮

// commitEditingStyle:传入提交的编辑操作(删除/添加)

// forRowAtIndexPath:当前正在编辑的行

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

 

// 该方法用于删除tableview上指定行的cell

// 注意:使用该方法的时候,模型中删除的数据的条数必须和deleteRowsAtIndexPaths方法中删除的条数一致,否则会报错

// 简而言之,就删除的数据必须和删除的cell保持一致

[self.tableViewdeleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationTop];

 

// 用于告诉系统开启的编辑模式是什么模式

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

 

2.UITabBarController的简单使用

UITabBarController的使用步骤

(1)初始化UITabBarController

(2)设置UIWindow的rootViewController为UITabBarController

(3)根据具体情况,通过addChildViewController方法添加对应个数的子控制器

 

4.UITabBarController的子控制器

UITabBarController添加控制器的方式有2种

添加单个子控制器

- (void)addChildViewController:(UIViewController *)childController;

 

设置子控制器数组

@property(nonatomic,copy)NSArray*viewControllers;

 

5.UITabBarButton

UITabBarButton里面显示什么内容,由对应子控制器的tabBarItem属性决定

 

UITabBarItem有以下属性影响着UITabBarButton的内容

标题文字

@property(nonatomic,copy)NSString *title;

图标

@property(nonatomic,retain)UIImage *image;

选中时的图标

@property(nonatomic,retain)UIImage *selectedImage;

提醒数字

@property(nonatomic,copy)NSString*badgeValue;


 

6.Modal

除了push之外,还有另外一种控制器的切换方式,那就是Modal

 

任何控制器都能通过Modal的形式展示出来

 

Modal的默认效果:新控制器从屏幕的最底部往上钻,直到盖住之前的控制器为止

 

以Modal的形式展示控制器

- (void)presentViewController:(UIViewController *)viewControllerToPresentanimated: (BOOL)flag completion:(void (^)(void))completion

 

关闭当初Modal出来的控制器

-  (void)dismissViewControllerAnimated: (BOOL)flag completion: (void(^)(void))completion;

 

7.tableView刷新、@property属性补充知识

1.tableView的刷新

1> 数据刷新的总体步骤

* 修改模型数据

* 刷新表格(刷新界面)

 

2> 刷新表格(刷新界面)的方法

* 全局刷新(每一行都会重新刷新)

- (void)reloadData;

 

* 局部刷新(使用前提: 刷新前后, 模型数据的个数不变)

- (void)reloadRows:(NSArray*)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;

 

* 局部删除(使用前提: 模型数据减少的个数 == indexPaths的长度)

- (void)deleteRowsAtIndexPaths:(NSArray*)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;

 

2.@property属性的用法

* weak(assign) :  代理\UI控件

* strong(retain) : 其他对象(除代理\UI控件\字符串以外的对象)

* copy : 字符串

* assign : 非对象类型(基本数据类型int\float\BOOL\枚举\结构体)

 

0 0
原创粉丝点击