gpt4 book ai didi

iphone - TableView :willDisplayHeaderView:inSection: not called when running for iOS 6. 1

转载 作者:太空狗 更新时间:2023-10-30 03:36:40 26 4
gpt4 key购买 nike

我没有在 stackoverflow 上找到类似的问题,所以我将针对该问题发布我自己的问题(如果有什么不明白的地方请告诉我):

问题:

我在自定义 UITableViewController 中使用带有 A-Z 部分标题的通用索引 tableView(如在 contacts.app 中)。我覆盖 tableView:viewForHeaderInSection: 以提供我自己的节标题 View 。

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

我覆盖了这些方法(自 iOS 6.0 起可用),它们完全满足我的需要:

  1. tableView:didEndDisplayingHeaderView:forSection:

  2. tableView:willDisplayHeaderView:forSection:

<强>2。向上/向下滚动 tableView 时永远不会调用方法 1, 而每次节标题从屏幕上消失时都会调用方法 1。

我不知道为什么一个被调用而另一个没有。这是苹果的错误还是我做错了什么?


类似问题:

我在这里发现了一个类似的问题 How to call a method “willDisplayFooterView” during Table View cusomization?其中一个答案是这样的:

They will only be called under iOS 6.0 or later and only if you also implement the other header/footer title/view methods. If you are providing a header or footer, there is no need for these to be called

我不确定我是否理解正确的答案,但如果是的话,在子类中实现哪些方法似乎很重要。


代码:

我只发布了我的 tableViewController 的非空重写委托(delegate)和数据源方法:

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)

@interface tvcB : tvcA
...
@end

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

最佳答案

我想我现在明白了。

Similar Question上面已经给出了答案,我没答对:

[...] If you are providing a header or footer, there is no need for these to be called

(对于“这些”,他可能指的是我在上面覆盖的两种方法。)

因为我确实提供了自己的节标题,而不是方法tableView:willDisplayHeaderView:forSection:,另一个覆盖方法:tableView:viewForHeaderInSection: 每次节标题进入屏幕时都会被调用。

所以最后我将在最后提到的方法中进行我需要的配置。

关于iphone - TableView :willDisplayHeaderView:inSection: not called when running for iOS 6. 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17026692/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com