美文网首页
UITableViewController

UITableViewController

作者: Rayla_周周 | 来源:发表于2016-07-22 13:36 被阅读0次

1> tableView没有cell的时候不显示空白横线

       self.tableView.tableFooterView = [[UIView alloc] init];

2> 如果有导航栏,滚动tableView的时候,隐藏导航栏

       self.navigationController.hidesBarsOnSwipe = YES;

3> 设置cell右侧的箭头标志

       cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

4> 设置导航栏标题

        self.navigationItem.title = @"红色";

         self.navigationItem.titleView = 只要继承了UIView的控件就行

 5> 让分割线满屏

     方法一:

        1.1 在创建tableView的时候设置

               self.tableView.separatorInset = UIEdgeInsetsZero;

               self.tableView.layoutMargins = UIEdgeInsetsZero;

         1.2 在创建cell的时候也要设置

               cell.separatorInset = UIEdgeInsetsZero;

               cell.layoutMargins = UIEdgeInsetsZero;

   方法二:

        2.1 在创建tableView的时候设置

              self.tableView.separatorInset = UIEdgeInsetsZero;

               self.tableView.layoutMargins = UIEdgeInsetsZero;

        2.2 在创建cell的时候设置(根据创建cell的方法不同,设置方式也不用)

        2.2.1 使用XIB 或 原型cell创建的时候

                 - (void)awakeFromNib

                 {

                     self.separatorInset = UIEdgeInsetsZero;

                     self.layoutMargins = UIEdgeInsetsZero;

                  }

       2.2.2 使用纯代码创建cell的时候

               - (instancetype)initWithFrame:(CGRect)frame

                 {

                     if (self = [super initWithFrame:frame]) {

                        self.separatorInset = UIEdgeInsetsZero;

                        self.layoutMargins = UIEdgeInsetsZero;

                      }

                   return self;

                  }

6> 使用原型cell创建cell,当可重用标识符设置正确,不会执行if判断,如果写错了会执行if判

      断,而且会覆盖之前的cell样式

       // 创建cell的标识 : ios3.0    可要可不要,写了会占用一点点内存

      Static NSString *ID = @"cell";

       UITableViewCell *cell = [tableView dequeueResableCellWithIdentifier:ID];

        // 这个方法是SB的标准方法,非常严谨,如果标识写错后,会直接崩溃,不会执行之后

             的判断操作

         UITableViewCell *cell = [tableView dequeueResableCellWithIdentifier:ID          forIndexPath:index];

7> 获取当前选中的cell的indexPath 和 cell

     NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

     UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

8> 获取屏幕上可见cell

    NSArray<NSIndexPath *> *indexPathArr =[self.tableView indexPathsForVisibleRows];

    注:indexPathArr中放的都是可见cell的位置indexPath

9> 页面滚动的时候关闭键盘

    self.tableView.alwaysBounceVertical = YES;

    self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;

10> 设置滚动到某个位置

        滚动的位置:

        NSIndexPath *indexPath1 = [NSIndexPath indexPathWithIndex:2];

        NSIndexPath *indexPath2 = [NSIndexPath indexPathForRow:2 inSection:0];

        // 常用于collectionView的滚动

        NSIndexPath *indexPath3 = [NSIndexPath indexPathForItem:2 inSection:0]; 

        滚动:

         [self.tableView setContentOffset:CGPointMake(100, 0) animated:YES];

         [self.tableView scrollToRowAtIndexPath:indexPath1 atScrollPosition:UITableViewScrollPositionNone animated:YES];

         [self.tableView selectRowAtIndexPath:indexPath2 animated:YES scrollPosition:UITableViewScrollPositionNone];

11 > 设置分割线的样式 和颜色

     /*

          线的样式种类:

          UITableViewCellSeparatorStyleNone,

          UITableViewCellSeparatorStyleSingleLine,

           UITableViewCellSeparatorStyleSingleLineEtched

        */

    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

     self.tableView.separatorColor = [UIColor blueColor];

12 > 获取自定义cell中textField所在的cell,方便做键盘处理

相关文章

网友评论

      本文标题:UITableViewController

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