基础

作者: wq04200 | 来源:发表于2016-11-03 22:20 被阅读17次

tableView:协议

UITableViewDataSource:

  //每个section上面的标语内容
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
//每个section下面的标语内容
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;

// Editing//是否可编辑
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;

// Moving/reordering
// 是否可拖拽
-tableView:moveRowAtIndexPath:toIndexPath:
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath;

// Index//右侧索引条需要的数组内容
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView;                                                  
 // return list of section titles to display in section index view (e.g. "ABCD...Z#")

//索引值对应的section-index
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index;  
// tell table which section corresponds to section title/index (e.g. "B",1)) 

// Data manipulation - insert and delete support
// 对Cell编辑后的回调
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;

// 对Cell拖拽后的回调
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath;

UITableViewDelegate(常用)

//将要展示Cell/header/Footer视图回调
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);
- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);
//完成展示Cell/header/Footer视图回调
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath NS_AVAILABLE_IOS(6_0);
- (void)tableView:(UITableView *)tableView didEndDisplayingHeaderView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);
- (void)tableView:(UITableView *)tableView didEndDisplayingFooterView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);

导航栏

导航控制器的创建和controller的管理

导航控制器是一个堆栈结构,只是其中管理的对象是controller,通过push与pop进行controller的切换,我们有两种方式可以创建导航控制器:

//通过一个自定义的导航栏和工具栏创建导航控制器
- (instancetype)initWithNavigationBarClass:(nullable Class)navigationBarClass toolbarClass:(nullable Class)toolbarClass;
//使用系统默认的导航栏和工具栏,通过一个根视图创建导航控制器
- (instancetype)initWithRootViewController:(UIViewController *)rootViewController;

通过以下方法对视图控制器进行管理操作:

//设置管理的视图控制器
- (void)setViewControllers:(NSArray<UIViewController *> *)viewControllers animated:(BOOL)animated;
//压入新的视图控制器
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;
//弹出一个视图控制器 返回的是pop的controller
- (nullable UIViewController *)popViewControllerAnimated:(BOOL)animated;
//弹出到某个视图控制器 返回所有pop的controller
- (nullable NSArray<__kindof UIViewController *> *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated;
 //直接pop到根视图控制器,返回所有被pop的controller
- (nullable NSArray<__kindof UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated;

导航控制器中的常用方法和属性

//返回栈顶的controller
@property(nullable, nonatomic,readonly,strong) UIViewController *topViewController; 
//返回显示的controller
@property(nullable, nonatomic,readonly,strong) UIViewController *visibleViewController;

上面两个方法的区别在于,topViewController是返回被push出的最后一个controller,但是如果之后又有present进行莫泰跳转,visibleViewController会返回当前显示的controller。例如A-push-B-present-C,则topViewController会返回B,visibleViewController会返回C。

//返回堆栈中所有的controller
@property(nonatomic,copy) NSArray<__kindof UIViewController *> *viewControllers;
//设置隐藏导航栏
@property(nonatomic,getter=isNavigationBarHidden) BOOL navigationBarHidden;
- (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated;
//导航栏对象,只读属性
@property(nonatomic,readonly) UINavigationBar *navigationBar;
//隐藏状态栏
@property(nonatomic,getter=isToolbarHidden) BOOL toolbarHidden NS_AVAILABLE_IOS(3_0);
- (void)setToolbarHidden:(BOOL)hidden animated:(BOOL)animated;
//状态栏对象
@property(null_resettable,nonatomic,readonly) UIToolbar *toolbar;
//导航中的返回手势对象
//iOS7之后,在导航中右划会进行pop操作,设置这个的enable可以控制设置手势是否失效
@property(nullable, nonatomic, readonly) UIGestureRecognizer *interactivePopGestureRecognizer;

iOS8后导航的新特性

//这个方法是为了iOS方法的命名统一,在导航中,其作用和push一样
- (void)showViewController:(UIViewController *)vc sender:(nullable id)sender;
//弹出键盘的时候隐藏导航栏
@property (nonatomic, readwrite, assign) BOOL hidesBarsWhenKeyboardAppears;
//屏幕滑动的时候隐藏导航栏,常用于tableView,上滑隐藏导航栏,下滑显示,带动画效果
@property (nonatomic, readwrite, assign) BOOL hidesBarsOnSwipe;
//滑动隐藏导航栏的手势
@property (nonatomic, readonly, strong) UIPanGestureRecognizer *barHideOnSwipeGestureRecognizer;
//横屏的时候隐藏导航栏
@property (nonatomic, readwrite, assign) BOOL hidesBarsWhenVerticallyCompact;
//敲击屏幕可以隐藏与显示导航栏
@property (nonatomic, readwrite, assign) BOOL hidesBarsOnTap;
//敲击屏幕的手势
@property (nonatomic, readonly, assign) UITapGestureRecognizer *barHideOnTapGestureRecognizer;

UINavigationDelegate

导航控制器还提供了一些代理回调方法,如下:

//视图将要展示时调用的方法
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
//视图已经展示时调用的方法
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
//设置方法设置导航控制器支持的设备方向
- (UIInterfaceOrientationMask)navigationControllerSupportedInterfaceOrientations:(UINavigationController *)navigationController NS_AVAILABLE_IOS(7_0);
//这个方法设置导航控制器的首选设备方向
- (UIInterfaceOrientation)navigationControllerPreferredInterfaceOrientationForPresentation:(UINavigationController *)navigationController NS_AVAILABLE_IOS(7_0);
//下面两个方法可以对导航的转场动画进行设置
- (nullable id <UIViewControllerInteractiveTransitioning>)navigationController:(UINavigationController *)navigationController interactionControllerForAnimationController:(id <UIViewControllerAnimatedTransitioning>) animationController;
- (nullable id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC ;

与UIViewController相关

//当前controller对应的导航项
@property(nonatomic,readonly,strong) UINavigationItem *navigationItem;
//push的时候隐藏底部栏,如push后隐藏tabbar
@property(nonatomic) BOOL hidesBottomBarWhenPushed;
//管理它的导航控制器
@property(nullable, nonatomic,readonly,strong) UINavigationController *navigationController;

相关文章

  • 机械设备安装技术

    设备基础种类及应用 垫层基础允许产生沉降:大型储罐 浅基础扩展基础联合基础:轧机独立基础 深基础桩基础:适用于需要...

  • 基础,基础,基础

    如果有人现在问我,JAVA该怎么学,我会告诉他不要急于求成,少看视频,多练,多思考。但说到这里有人可能会反...

  • 【Android】知识点汇总,坚持原创ing

    Android基础 Java基础 Java基础——Java内存模型和垃圾回收机制 语法基础 语法基础——C语法基础...

  • Java 基础

    Java 基础01Java开发入门 Java 基础02Java编程基础 Java 基础03面向对象 Java 基础...

  • 零基础学画画从入门到放弃

    零基础应该怎么学画画?零基础那就从基础开始学啊!基础是什么?造型基础和色彩基础。 造型基础就是用点线面组成起码能让...

  • 面试题汇总

    1.Java基础面试问题 Java基础之基础问题 Java基础之面向对象 Java基础之数据结构 Java基础之I...

  • 基础基础还是基础

    这次去面试,还是被基础给打趴下了。 对于PHP7的新特性没有了解。 对于TP的新特性没有了解。 再一个就是独立完成...

  • 零基础学UI设计需要美术基础吗?

    零基础学UI设计需要美术基础吗?零基础学UI设计需要美术基础吗?零基础学UI设计需要美术基础吗?零基础学UI设计需...

  • 基础基础!

    人生中第一个自主设计的实验方案终于得到认可^O^在设计方案过程中认识到基础知识以及细心的重要性,还有半个学期可以努...

  • Go语言基础语法--注释、基础结构2

    章节 GO语言基础语法--注释、基础结构(重要) 1.GO语言基础语法---注释、基础结构 基础结构注意事项 源文...

网友评论

      本文标题:基础

      本文链接:https://www.haomeiwen.com/subject/xskyuttx.html