(ExpandableTableView *)tableView heightForRowAtIndexPath :( NSIndexPath *)未调用

时间:2014-03-10 12:56:20

标签: ios objective-c uitableview

我正在使用库来制作可扩展的tableview  这是图书馆

https://github.com/wannabegeek/ExpandableTableView

我想要做的是改变子行的行高  但是

- (CGFloat)tableView:(ExpandableTableView *)tableView heightForSection:(NSUInteger)section;
- (CGFloat)tableView:(ExpandableTableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;

从未打过电话

我从委托类

取消注释它们

我该怎么办?

4 个答案:

答案 0 :(得分:1)

尝试此自定义代理:

步骤1:在 ExpandableTableViewDelegate.h

中取消注释这些行
- (CGFloat)tableView:(ExpandableTableView *)tableView heightForSection:(NSUInteger)section;
- (CGFloat)tableView:(ExpandableTableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;

第2步:在 ExpandableTableView.h

中添加以下行
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- (CGFloat)tableView:(UITableView *)tableView heightForSection:(NSUInteger)section;

第3步:在 ExpandableTableView.m

中添加以下行
- (CGFloat)tableView:(UITableView *)tableView heightForSection:(NSUInteger)section
{
    return 100;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}

步骤4:现在将以下行添加到 ExampleController.m

- (CGFloat)tableView:(ExpandableTableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100; //return custom height value
} 

- (CGFloat)tableView:(ExpandableTableView *)tableView heightForSection:(NSUInteger)section;
{
    return 100; //return custom height value
}

答案 1 :(得分:0)

委托方法

- (CGFloat)tableView:(ExpandableTableView *)tableView heightForSection:(NSUInteger)section;
- (CGFloat)tableView:(ExpandableTableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;

永远不会被调用,因为他们没有实现它们。

见 - ExpandableTableView第22,23行

答案 2 :(得分:0)

全部谢谢

解决了

在expandableTableView.m

中实现此方法

https://github.com/jasonparekh/ExpandableTableView/commit/7eccd302a2edb42d950bed58de0657a0e16f1bd8

然后这个方法被称为

答案 3 :(得分:-1)

查看您为库提供的链接,似乎作者已注释掉并且未从委托中实现这些方法。他网站上的一些评论是人们告诉他他们需要自己实施这些方法但却无法实现。

@protocol ExpandableTableViewDelegate <NSObject>

@optional
- (void)tableView:(ExpandableTableView *)tableView willExpandSection:(NSUInteger)section;
- (void)tableView:(ExpandableTableView *)tableView didExpandSection:(NSUInteger)section;
- (void)tableView:(ExpandableTableView *)tableView willContractSection:(NSUInteger)section;
- (void)tableView:(ExpandableTableView *)tableView didContractSection:(NSUInteger)section;

- (BOOL)tableView:(ExpandableTableView *)tableView canRemoveSection:(NSUInteger)section;

//- (CGFloat)tableView:(ExpandableTableView *)tableView heightForSection:(NSUInteger)section;
//- (CGFloat)tableView:(ExpandableTableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSInteger)tableView:(ExpandableTableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(ExpandableTableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(ExpandableTableView *)tableView willDisplayCell:(UITableViewCell *)cell forSection:(NSUInteger)section;