ios - [ComponentTaleView tableView :heightForFooterInSection:]: unrecognized selector sent to instance

标签 ios objective-c tableview

我正在调试一个 iOS 应用程序(不是 iOS 开发人员)来尝试为客户解决一个错误,因为我们的 iOS 开发人员不在,所以很抱歉,因为这可能是显而易见的。该应用程序崩溃并显示以下错误消息:

2019-06-03 16:34:05.292250+0100 SBD POP[75510:2099884] -[ComponentTableView tableView:heightForFooterInSection:]: unrecognized selector sent to instance 0x7f901d929200
2019-06-03 16:34:05.298376+0100 SBD POP[75510:2099884] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ComponentTableView tableView:heightForFooterInSection:]: unrecognized selector sent to instance 0x7f901d929200'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001126da6fb __exceptionPreprocess + 331
    1   libobjc.A.dylib                     0x00000001116fdac5 objc_exception_throw + 48
    2   CoreFoundation                      0x00000001126f8ab4 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    3   UIKitCore                           0x000000011c8a0c3d -[UIResponder doesNotRecognizeSelector:] + 287
    4   CoreFoundation                      0x00000001126df1a1 ___forwarding___ + 769
    5   CoreFoundation                      0x00000001126e1238 _CF_forwarding_prep_0 + 120
    6   SBD POP                             0x000000010d1852b6 -[ComponentTableView tableView:heightForFooterInSection:] + 230
    7   UIKitCore                           0x000000011cab6106 -[UITableView _classicHeightForFooterInSection:] + 167
    8   UIKitCore                           0x000000011cabb02c -[UITableView _heightForFooterInSection:] + 34
    9   UIKitCore                           0x000000011cacabc4 -[UISectionRowData heightForFooterInSection:canGuess:] + 91
    10  UIKitCore                           0x000000011cad2277 -[UITableViewRowData rectForFooterInSection:heightCanBeGuessed:] + 653
    11  UIKitCore                           0x000000011ca890d7 -[UITableView _rectForFooterInSection:usingPresentationValues:] + 166
    12  UIKitCore                           0x000000011cab169e -[UITableView _hasHeaderFooterBelowRowAtIndexPath:] + 175
    13  UIKitCore                           0x000000011ca90c2f -[UITableView _shouldDrawSeparatorAtBottomOfSection:] + 126
    14  UIKitCore                           0x000000011caacf3d -[UITableView _setupCell:forEditing:atIndexPath:canEdit:editingStyle:shouldIndentWhileEditing:showsReorderControl:accessoryType:animated:updateSeparators:] + 1264
    15  UIKitCore                           0x000000011caad23f -[UITableView _setupCell:forEditing:atIndexPath:animated:updateSeparators:] + 665
    16  UIKitCore                           0x000000011ca9b3cb __53-[UITableView _configureCellForDisplay:forIndexPath:]_block_invoke + 2569
    17  UIKitCore                           0x000000011cd34a19 +[UIView(Animation) performWithoutAnimation:] + 90
    18  UIKitCore                           0x000000011ca9a8db -[UITableView _configureCellForDisplay:forIndexPath:] + 237
    19  UIKitCore                           0x000000011caad6bf -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 911
    20  UIKitCore                           0x000000011caadb65 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 73
    21  UIKitCore                           0x000000011ca75d20 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2870
    22  UIKitCore                           0x000000011ca95e37 -[UITableView layoutSubviews] + 165
    23  UIKitCore                           0x000000011cd429c1 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1417
    24  QuartzCore                          0x000000010e051eae -[CALayer layoutSublayers] + 173
    25  QuartzCore                          0x000000010e056b88 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 396
    26  UIKitCore                           0x000000011cd2d985 -[UIView(Hierarchy) layoutBelowIfNeeded] + 646
    27  UIKitCore                           0x000000011c1d5ec8 -[UINavigationController _layoutViewController:] + 1756
    28  UIKitCore                           0x000000011c1cfad8 -[UINavigationController _layoutTopViewController] + 223
    29  UIKitCore                           0x000000011c1cde01 -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 732
    30  UIKitCore                           0x000000011ccfa4b6 -[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:] + 418
    31  UIKitCore                           0x000000011ccfa779 -[UINavigationTransitionView _cleanupTransition] + 608
    32  UIKitCore                           0x000000011cd098ff -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 343
    33  UIKitCore                           0x000000011cd0516d +[UIViewAnimationState popAnimationState] + 319
    34  UIKitCore                           0x000000011ccfa229 -[UINavigationTransitionView transition:fromView:toView:] + 2363
    35  UIKitCore                           0x000000011c1d6efb -[UINavigationController _startTransition:fromViewController:toViewController:] + 3222
    36  UIKitCore                           0x000000011c1d73b5 -[UINavigationController _startDeferredTransitionIfNeeded:] + 896
    37  UIKitCore                           0x000000011c1d86a7 -[UINavigationController __viewWillLayoutSubviews] + 150
    38  UIKitCore                           0x000000011c1b938d -[UILayoutContainerView layoutSubviews] + 217
    39  UIKitCore                           0x000000011cd429c1 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1417
    40  QuartzCore                          0x000000010e051eae -[CALayer layoutSublayers] + 173
    41  QuartzCore                          0x000000010e056b88 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 396
    42  QuartzCore                          0x000000010e062ee4 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 72
    43  QuartzCore                          0x000000010dfd23aa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 328
    44  QuartzCore                          0x000000010e009584 _ZN2CA11Transaction6commitEv + 608
    45  UIKitCore                           0x000000011c86ed8a _UIApplicationFlushRunLoopCATransactionIfTooLate + 150
    46  UIKitCore                           0x000000011c961f5f __handleEventQueueInternal + 6845
    47  CoreFoundation                      0x0000000112641be1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    48  CoreFoundation                      0x0000000112641463 __CFRunLoopDoSources0 + 243
    49  CoreFoundation                      0x000000011263bb1f __CFRunLoopRun + 1231
    50  CoreFoundation                      0x000000011263b302 CFRunLoopRunSpecific + 626
    51  GraphicsServices                    0x0000000117f812fe GSEventRunModal + 65
    52  UIKitCore                           0x000000011c874ba2 UIApplicationMain + 140
    53  SBD POP                             0x000000010d16fc00 main + 112
    54  libdyld.dylib                       0x000000011606f541 start + 1
    55  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

我已经将问题追溯到这个函数(打印语句是我的):

#import "ComponentTableView.h"

#import "Component.h"
#import "CoreData.h"

#import "UIPositioning.h"
#import "UIView+utils.h"
#import "UIColor+appColors.h"
#import "TotalRowView.h"

#import "NSUserDefaults+Preferences.h"

@implementation ComponentTableView

//Other code/functions here

#pragma mark - UITableViewDelegate

//Other code/functions here

-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    printf("Section: %f\n", section);
    switch (section) {
        case 0:
        {
            printf("Section - Case 0\n");
            if([self showSectionFooters])
            {
                printf("Section - Case 0 - If Statement\n");
                return [super tableView:tableView heightForFooterInSection:section];
            }
            break;
        }
        case 1:
        {
            printf("Section - Case 1\n");
            return [super tableView:tableView heightForFooterInSection:section];
            break;
        }
        default:
        {
            printf("Section - Default\n");
            break;
        }
    }

    return 0;
}

ComponentTableView.h

#import "DisplayItemTableView.h"


@class ComponentTableView;

@protocol ComponentTableViewDelegate <NSObject>
- (void)onComponentTableControllerDidChangeContent:(ComponentTableView*) componentTableView;
@optional
- (void)onComponentTableViewEdit:(ComponentTableView*) componentTableView;
- (void)onDisplayItemTableVerifiedComponentsChanged:(ComponentTableView*) componentTableView;
@end

@interface ComponentTableView : DisplayItemTableView <DisplayItemViewDelegate>
@property BOOL includePreviewImage;
@property BOOL standComponentIsMandatory;
-(BOOL) outOfStock;
@property (strong, nonatomic) NSCountedSet<NSString*>* verifiedComponentSet;
@property (weak, nonatomic) id<ComponentTableViewDelegate> parentDelegate;
@property (strong, nonatomic) Component* stand;

-(CGFloat) contentHeight;
-(CGFloat) retailCost;
-(CGFloat) merchCost;
- (id) initWithComponentUIDSet:(NSCountedSet<NSString*> *) componentUIDSet;

+(CGFloat) contentHeight:(NSCountedSet*) uidset;

@end

DisplayItemTableView.h

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#import "DisplayItemView.h"
#import "TotalRowView.h"

@class DisplayItemTableView;


@interface DisplayItemTableView : UITableView<UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate>
@property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController;

@property (strong, nonatomic) RetailTotalView *retailTotalView;
@property (strong, nonatomic) MerchandisingTotalView *merchTotalView;

-(id) initWithHeight:(CGFloat) height;
-(id) initWithTopAndHeight:(CGFloat) top :(CGFloat) height;

+(CGFloat) displayItemHeight:(NSString*) name :(NSString*) sku :(BOOL) includePreviewImage;
+(UIColor*) separatorColor;
@end

在打开控制台打印的情况下进行测试让我知道这是返回语句:

return [super tableView:tableView heightForFooterInSection:section];

这会导致未注册的选择器错误 - 如果我注释掉 case0/case1 并保留默认值,应用程序会正常运行,但生成的表格格式不正确。有人有什么想法吗?

最佳答案

UITableView 没有实现与 UITableViewDelegate 的一致性,因此它不保证它提供方法 -tableView:heightForFooterInSection:。但是,当 ComponentTableView 调用 super 时,它会尝试准确找到该方法。当父类(super class)未实现时,您无法向 super 发送消息。

与其发送到 super 以获取“默认”值,不如考虑您实际想要的值是什么。如果它是“无页脚”,只需从 ComponentTableView 的实现中返回 0。如果它“不管自动布局说的多高”,返回 UITableViewAutomaticDimension

最后一点:许多 iOS 应用程序都将 TableView 与其委托(delegate)和数据源分开。您可能需要考虑使用 View Controller 或其他对象作为委托(delegate),而不是继承 UITableView 来实现这些协议(protocol)。

关于ios - [ComponentTaleView tableView :heightForFooterInSection:]: unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56430594/

相关文章:

IOS:创建 UIBarButtonItem 后如何重置它的操作?

android - 如何找到适用于 Android 和 iOS 的可信证书?

ios - 当我在一个 View Controller 中有 2 个 TableView 时,不会为第二个 UITableView 调用 cellForRowAtIndexPath

ios - 分别从所有 UITableViewCells 获取数据

ios - 如何在 Swift 中调整 TableView 标题的缩进?

java - JavaFX tableView 中的导航

objective-c - Xcode-将超链接添加到电子邮件

objective-c - block 在异步线程上执行两次

java - 使用 JNI 从 Cocoa 调用 Java 类函数

objective-c - Objective-C : How to set the subview display in the current visible frame?(UITableView)