zoukankan      html  css  js  c++  java
  • UITableView UITableViewCell NSIndexPath

     

    --------------------------------------------------------------------------NSIndexPath-------------------------------------------------------------------------

    1:初始化NSIndexPath (来自: Kid)

    inSection 表示TableView 的分组的 第一组数据.

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];  

    2:IndexPath 对比是否相同

    [easyTableView.selectedIndexPath isEqual:indexPath]  

    3:通过UITableViewCell 里面的按钮事件 来获取 该按钮所在的IndexPath

    1:注册事件:

        [selectButton addTarget:self action:@selector(FE_selectAnnotation:withEvent:) forControlEvents:UIControlEventTouchUpInside];  
    注:@selector 可以获取 UIEvent 对象
        NSIndexPath *indexPath = [tableView indexPathForRowAtPoint: [[[event touchesForView: btn] anyObject] locationInView:tableView]];  
        NSLog(@"%d",indexPath.row);  


    --------------------------------------------------------------------------NSIndexPath--------------------------------------------------------------------------


    ------------------------------------------------------------------------------------UITableView------------------------------------------------------------------------------------------

    1:UITableView reLoadData 重载动态数据时的注意.

    因为UITableView的Cell  是以重用的方式去显示数据,所以对Cell中动态数据 都需要设置. 否则可能会乱掉

    2:去除选中某行Cell的状态

    [tableView deselectRowAtIndexPath:indexPath animated:YES];  
    3:使用静态UITableView时此委托不要实现,否则在运行时将出现警告
        -(UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath  
        {  
            if ([indexPath row] == 0) {  
                return UITableViewCellAccessoryDisclosureIndicator;  
            }else {  
                return UITableViewCellAccessoryNone;  
            }  
        }  

    4:滑动删除按钮必须同时实现以下两个委托,才能生效

        -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath  
        {  
            return YES;  
        }  
        -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {   
            NSLog(@"%d",indexPath.row);     
        }  

    5:在使用UITableView 的

    tableHeaderView 时 丢进去的View需要先行设置好 Frame  不然会与后面生成Cell产生重叠的问题

    6:UITableView 默认 只支持垂直 可以通过transForm 旋转达到支持水平形式的UITableView

    1:网上开源Demo下载地址:


    从iOS6以上开始  有了UITableView的亲兄弟 UICollectionView.  它带来更加强大的布局功能.



    7:提前获取UITableView 的ContentSize

    [flowCalendarTableView.tableView layoutIfNeeded];  
    NSLog(@"%@",NSStringFromCGSize(flowCalendarTableView.tableView.contentSize)); 
     
    8: 去掉UITabelView 默认的 Cell间隔线条
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;  
    9: 下拉刷新实现原理
    在UITableView 上面 addSubView 一个 -y 轴的 RefreshView 上去后,那么在拖动TableView的时候 就可以看到刚刚加上去的View
    那么此时在ScrollView拖动委托中 进行判断,监听拖拽度足够的情况下触发刷新事件.
    在触发事件的同时,修改 contentInset 来保证 RefreshView能够突显出来,顺应其他Cell的拖动显示.
    此处记录一点,就是在包含 Section View 的时候 需要加入以下代码,才能保证正常的拖动效果,以不至于出现灵异的拖动显示效果
        CGFloat offset = MAX(scrollView.contentOffset.y * -1, 0);  
        offset = MIN(offset, 60);  
        scrollView.contentInset = UIEdgeInsetsMake(offset, 0.0f, 0.0f, 0.0f);  
    注:以上代码通用,无需过多考虑其原理.

    10:开启排序拖动编辑功能
        //开启排序拖动编辑功能  
        - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath  
        {  
            NSLog(@"1");  
        }  
    11:滑动显示删除按钮时和结束按钮操作时所触发的委托,可以在这两个委托里面控制 Cell内部Frame
        - (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath  
        {  
            [UIView animateWithDuration:0.25 animations:^{  
                FEUIFriendGroupCell *cell = (FEUIFriendGroupCell *)[tableView cellForRowAtIndexPath:indexPath];  
                cell.friendGroupTitleTextField.Help_width -=60;  
            }];  
        }  
        - (void)tableView:(UITableView *)tableView  didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath  
        {  
            [UIView animateWithDuration:0.25 animations:^{  
                FEUIFriendGroupCell *cell = (FEUIFriendGroupCell *)[tableView cellForRowAtIndexPath:indexPath];  
                cell.friendGroupTitleTextField.Help_width +=60;  
            }];  
        }  
    注:删除按钮出来时肯定有动画,但是消失时不一定有动画,原因是看你有没有实现 这个委托 accessoryTypeForRowWithIndexPath(搜索一下)

    12:让UIPanGestureRecognizer 与 UItableView 的滑动显示 删除按钮  共存

        [[tableView gestureRecognizers] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {  
            if ([NSStringFromClass([obj class]) isEqualToString:@"UISwipeGestureRecognizer"]) {  
                  [self.bookContentContainerView.touchPanGesture requireGestureRecognizerToFail:obj];  
            }  
           
        }];  
    13:开启UITableView多选编辑功能(iOS 5 or later):
        [multiFTPServerListTableView setAllowsMultipleSelectionDuringEditing:YES];  
        [multiFTPServerListTableView setEditing:YES];  
    在多选状态下,实现单选功能:
        - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath  
        {  
            NSLog(@"%@",[tableView indexPathsForSelectedRows]);  
            NSArray *indexPathArray = [tableView indexPathsForSelectedRows];  
            [indexPathArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {  
                if ([indexPath isEqual:obj] == NO) {  
                    [tableView deselectRowAtIndexPath:obj animated:NO];  
                }  
            }];  
        }  
    14:让已经选择了多个Cell以后立刻去除所有已选中的效果:
        _documentCollectionView.allowsMultipleSelection = NO;  
        _documentCollectionView.allowsSelection = NO;  
        _documentCollectionView.allowsSelection = YES;  




    ------------------------------------------------------------------------------------UITableView------------------------------------------------------------------------------------------

    ---------------------------------------------------------------------------------UITableViewCell---------------------------------------------------------------------------------------


    1:设置TableViewCell 的背景颜色

     

        UIView *backgrdView =[[UIView alloc] initWithFrame:self.frame];  
        backgrdView.backgroundColor=[UIColor colorWithRed:242.0/255 green:242.0/255 blue:242.0/255 alpha:1];  
        self.backgroundView= backgrdView;  
        [backgrdView release];  
    2:控制 自定义UITableViewCell 的 Cell 高度 不要超出显示范围的方式

    例如:Cell 高度 有100 但其实只有显示 50. 

    第一步是设置好UITableView 没列的高度,通过以下委托

        - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath  
        {  
            return 50;  
        }  
    第二步 将UITableViewCell 自身设置为 自动遮罩不可见区域
    [self.layer setMasksToBounds:YES];  

    3:为自定义UITableViewCell 设置  reuseIdentifier

    在Cell.h 头文件添加

    静态取值方法:

    + (NSString *)reuseIdentifier; 

    在Cell.m体文件添加
        //因为是继承关系 所以重写Cell 的 reuseIdentifier 以确定 其值.  
        -(NSString *)reuseIdentifier  
        {  
           return @"FEUIAddressBookCell";  
        }  
        //定义一个静态方法来取其值.  
        +(NSString *)reuseIdentifier  
        {  
           return @"FEUIAddressBookCell";  
        }  
    UITableView 调用时如下:
        NSString *SectionsTableIdentifier = [FEUIAddressBookCell reuseIdentifier];  
        FEUIAddressBookCell *addressBookCell = (FEUIAddressBookCell *)[tableView dequeueReusableCellWithIdentifier:SectionsTableIdentifier];  
        if(addressBookCell == nil)  
        {  
           NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"FEUIAddressBookCell" owner:self options:nil];  
           addressBookCell = (FEUIAddressBookCell *)[nib objectAtIndex:0];  
        }  

    通过如上,性能问题已经解决.继续施展拳脚吧!!!


    4:UITableView 在Grouped 模式下. 修改Cell 背景颜色的方式

    cell.backgroundColor = [UIColor whiteColor];  

    5:不要在Cell内部的任何控件 使用 setMasksToBounds, 否则拖动动画不流畅


    6:设置Cell系统高亮选择样式风格

    cell.selectionStyle = UITableViewCellSelectionStyleNone;  

    注:上面表示取消了.系统默认的高亮选择效果.

    ---------------------------------------------------------------------------------UITableViewCell---------------------------------------------------------------------------------------


  • 相关阅读:
    10000台不稳定机器如果做爬虫
    python 豆瓣高分电影爬虫
    恶意爬虫让机票价格暴涨 每年或致航空公司损失十多亿元
    python 豆瓣高分电影爬虫
    Python 爬虫保存图片
    你的爬虫票价价格暴涨
    10分钟教你利用Python网络爬虫获取穷游攻略
    10分钟教你利用Python网络爬虫获取穷游攻略
    SAP Cloud for Customer 如何直接消费S/4HANA API
    如何分辨 SAP Fiori Launchpad 里的真假 Fiori 应用
  • 原文地址:https://www.cnblogs.com/allanliu/p/4260345.html
Copyright © 2011-2022 走看看