Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone tableView:willDisplayHeaderView:inSection:在运行iOS 6.1时未调用_Iphone_Objective C_Ios6_Uitableview_Indexed - Fatal编程技术网

Iphone tableView:willDisplayHeaderView:inSection:在运行iOS 6.1时未调用

Iphone tableView:willDisplayHeaderView:inSection:在运行iOS 6.1时未调用,iphone,objective-c,ios6,uitableview,indexed,Iphone,Objective C,Ios6,Uitableview,Indexed,我没有找到关于stackoverflow的等效问题,因此我将针对该问题发布我自己的问题(如果有不可理解的地方,请告诉我): 问题: 我在自定义的UITableViewController中使用一个带有a-Z节头的通用索引tableView(如contacts.app中)。 我覆盖tableView:viewForHeaderInSection:以提供我自己的节头视图 当用户向上或向下滚动表格时,我需要倾听在表格视图顶部或底部出现/消失的部分标题(以相应地更改某些自定义视图) 我覆盖了这些方法(从

我没有找到关于stackoverflow的等效问题,因此我将针对该问题发布我自己的问题(如果有不可理解的地方,请告诉我):

问题: 我在自定义的
UITableViewController
中使用一个带有a-Z节头的通用索引
tableView
(如contacts.app中)。 我覆盖
tableView:viewForHeaderInSection:
以提供我自己的节头视图

当用户向上或向下滚动表格时,我需要倾听在表格视图顶部或底部出现/消失的部分标题(以相应地更改某些自定义视图)

我覆盖了这些方法(从iOS 6.0开始提供),它们完全满足我的需要:

  • tableView:didendisplayingheaderview:forSection:

  • 表格视图:willDisplayHeaderView:forSection:

  • 2。在向上/向下滚动tableView时,永远不会调用方法1,,而每次节头从屏幕上消失时,都会调用方法1

    我不知道为什么一个被叫,另一个不被叫。这是苹果的错误还是我做错了什么


    类似问题: 我在这里发现了一个类似的问题 其中一个答案是:

    只有在iOS 6.0或更高版本下,并且只有在您还实现了其他页眉/页脚标题/视图方法时,才会调用它们。如果提供页眉或页脚,则无需调用它们

    我不确定我是否正确理解这个答案,但如果是这样,那么在子类中实现哪些方法似乎很重要


    代码: 我只发布我的
    tableViewController的非空重写委托和数据源方法

    tvcA.m

    @implementation tvcA 
    ...
    #pragma mark - Table view data source 
    
    - (NSArray *) sectionIndexTitlesForTableView : (UITableView *) tableView 
    {
        // returns sectionIndexArray with alphabet for example
    }
    
    - (UIView *) tableView : (UITableView *) tableView
    viewForHeaderInSection : (NSInteger) section 
    {
        MNSectionHeaderView* headerView = [[MNSectionHeaderView alloc] initWithFrame : CGRectMake(0, 0, 260, 22)];
        return headerView;
    }
    
    -     (NSInteger) tableView : (UITableView *) tableView
    sectionForSectionIndexTitle : (NSString *) title
                        atIndex : (NSInteger) index {...}
    ...
    @end
    
    tvcB.h(继承自tvcA)

    tvcB.m

    @implementation tvcB
    ...
    #pragma mark - Table view data source
    
    - (NSInteger) numberOfSectionsInTableView : (UITableView *) tableView {...}
    
    - (NSInteger) tableView : (UITableView *) tableView
      numberOfRowsInSection : (NSInteger) section {...}
    
    - (UITableViewCell*) tableView : (UITableView *) tableView
          cellForRowAtIndexPath : (NSIndexPath *) indexPath {...}
    
    - (CGFloat) tableView : (UITableView *) tableView
    heightForHeaderInSection : (NSInteger) section {...}
    
    - (UIView *) tableView : (UITableView *) tableView
    viewForHeaderInSection : (NSInteger) section {....}
    
    
    #pragma mark - Table view delegate
    
    -    (void) tableView : (UITableView*) tableView
    willDisplayHeaderView : (UIView*) view
           forSection : (NSInteger) section { 
        // custom configurations
    }
    
    -         (void) tableView : (UITableView*) tableView
    didEndDisplayingHeaderView : (UIView*) view
                    forSection : (NSInteger) section {
       // custom configurations    
    }
    
    - (void) tableView : (UITableView *) tableView
    didSelectRowAtIndexPath : (NSIndexPath *) indexPath {...}
    ...
    @end
    
    我想我现在明白了

    上面提到的已经给出了答案,但我没有得到正确的答案:

    […]如果提供页眉或页脚,则无需调用它们

    (他说的“这些”可能指的是我上面提到的两种方法。)

    因为我提供了自己的节头,而不是方法
    tableView:willDisplayHeaderView:forSection:
    ,另一种覆盖方法:
    tableView:viewForHeaderSection:
    在每次节头进入屏幕时都会被调用


    最后,我将使用上面提到的方法进行必要的配置。

    由于某种原因,在我的案例中,
    表格视图:viewForHeaderSection:
    被调用用于我所有表格的所有部分(我有一个包含大量表格的滚动视图)。所以你的解决方案对我不起作用。然而,由于我只需要知道VC弹出时哪个部分是第一个可见部分,所以我想出了一个很好的解决方案:

        NSInteger firstVisibleSection = 0;
        for (int i = 0; i < [_board.swimlanes count]; i++)
        {
            CGRect sectionRect = [currentTable rectForSection:i];
            BOOL containsPoint = CGRectContainsPoint(sectionRect, currentTable.contentOffset);
            if (containsPoint)
            {
                firstVisibleSection = i;
                break;
            }
        }
    
    NSInteger firstVisibleSection=0;
    对于(int i=0;i<[u board.swimlanes count];i++)
    {
    CGRect sectionRect=[currentTable rectForSection:i];
    BOOL containsPoint=CGRectContainsPoint(sectionRect,currentTable.contentOffset);
    如果(包含点)
    {
    firstVisibleSection=i;
    打破
    }
    }
    

    可能对有同样问题的人有帮助:)

    我想,您只想跟踪屏幕上可见的最上面的部分,对吗?当然:
    tableView:viewForHeaderInSection:
    每次屏幕上(重新)出现一个节头时都会被调用-在顶部和/或底部。跟踪顶部部分的一种更简单的方法是:添加一个类属性,如
    NSUInteger-topSection
    ,并在
    tableView:viewForHeaderInSection:
    中设置它,如:
    if(section<\u-topSection){\u-topSection=section;}
    tableView:dienddisplayingheaderview:forSection:nextsectionshow:
    if(节==\u上节){\u上节=nextSection;}
    。试试看-我试过了更容易-它不起作用。至少在我的情况下。我有一个页面滚动视图,每页都有一个表。当视图第一次出现时
    tableView:viewForHeaderInSection:
    会为所有headerView调用,而不仅仅是屏幕上的那些。另外,使用您建议的解决方案,您可以跟踪该部分l我在上面贴了一个,你只需要在需要的时候检查一下就可以了。好吧,我想,这两个解决方案(需要的时候检查/一直跟踪)可能在不同的情况下都有帮助(在我的情况下,我需要信息一直更新)。只是因为我很好奇:它不总是第一部分吗
    0
    第一次加载分页的滚动视图/表时显示在顶部?顺便问一下:您知道可以检查方法
    tableView:viewForHeaderInSection:
    调用的是哪个tableView,比如:
    if(tableView==self.searchDisplayController.searchResultsTableView)…
    ?不,当VC加载时,我将注意力集中在上一个会话中最后一次查看的泳道上。这就是我需要这些信息的原因;)这就是为什么我只在最后才需要它的原因。我并不是说我的解决方案是唯一的,但事实证明它对我来说是完美的,所以这就是为什么我在这里提供它。
        NSInteger firstVisibleSection = 0;
        for (int i = 0; i < [_board.swimlanes count]; i++)
        {
            CGRect sectionRect = [currentTable rectForSection:i];
            BOOL containsPoint = CGRectContainsPoint(sectionRect, currentTable.contentOffset);
            if (containsPoint)
            {
                firstVisibleSection = i;
                break;
            }
        }