简体   繁体   中英

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

I'm debugging an iOS app (not an iOS developer) to try and solve a bug for a client as our iOS dev is away so apologies as this is probably obvious. The app is crashing with the following error message:

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

I've tracked the problem down to this function (print statements are mine):

#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

Testing with the console prints turned on lets me know that it's the return statements:

return [super tableView:tableView heightForFooterInSection:section];

Which are causing the unregonised selector error - if I comment out case0/case1 and just leave the default the app functions but the table being generated isn't formatted correctly. Anyone have any ideas?

UITableView does not implement conformance to UITableViewDelegate, so it doesn't guarantee that it provides the method -tableView:heightForFooterInSection: . However, when ComponentTableView calls super , it's attempting to find exactly that method. You can't send a message to super when the superclass doesn't implement it.

Instead of sending to super to get a "default" value, think about what you actually want the value to be. If it's "no footer," simply return 0 from ComponentTableView's implementation. If it's "however tall Auto Layout says," return UITableViewAutomaticDimension .

One last note: many iOS apps make a point of separating the table view from its delegate and data source. You may want to consider using a view controller or other object as the delegate, instead of subclassing UITableView to implement those protocols.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM