1

I have a xib file called "BMSkipBreakButton.xib" that just contains a UILabel and a UIImageView.

enter image description here

I set the File Owner of this xib to a class called BMSkipBreakButtonView:

enter image description here

When I go to the Connections Inspector for the File Owner it shows up like this:

enter image description here

Each of UI elements in the XIB have a referencing outlet that connects to the File Owner. For example:

enter image description here

The class BMSkipBreakButtonView looks like this (the outlets are hooked up to the UI elements inside the XIB):

.h:


    #import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface BMSkipBreakButtonView : UIView

@property (nonatomic, strong) IBOutlet UILabel *skipBreakButtonText;
@property (nonatomic, strong) IBOutlet UIImageView *skipImageView;

@end

NS_ASSUME_NONNULL_END

The .m file looks like this:

#import "BMSkipBreakButtonView.h"

@interface BMSkipBreakButtonView ()
@property (nonatomic, strong) UIView *containerView;
@property (nonatomic, strong) NSMutableArray *customConstraints;
@end

@implementation BMSkipBreakButtonView

- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self commonInit];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self commonInit];
    }
    return self;
}

- (void)commonInit
{
    _customConstraints = [[NSMutableArray alloc] init];

    UIView *view = nil;
    NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"BMSkipBreakButton"
                                                     owner:self
                                                   options:nil];

    for (id object in objects) {
        if ([object isKindOfClass:[UIView class]]) {
            view = object;
            break;
        }
    }

    if (view != nil) {
        _containerView = view;
        view.translatesAutoresizingMaskIntoConstraints = NO;
        [self addSubview:view];
        [self setNeedsUpdateConstraints];
    }
}

- (void)updateConstraints
{
    [self removeConstraints:self.customConstraints];
    [self.customConstraints removeAllObjects];

    if (self.containerView != nil) {
        UIView *view = self.containerView;
        NSDictionary *views = NSDictionaryOfVariableBindings(view);

        [self.customConstraints addObjectsFromArray:
            [NSLayoutConstraint constraintsWithVisualFormat:
                @"H:|[view]|" options:0 metrics:nil views:views]];
        [self.customConstraints addObjectsFromArray:
            [NSLayoutConstraint constraintsWithVisualFormat:
                @"V:|[view]|" options:0 metrics:nil views:views]];

        [self addConstraints:self.customConstraints];
    }

    [super updateConstraints];
}

@end

The problem is that the app is crashing at the "loadNibNamed" method call (I set an exception breakpoint and the app stops at this breakpoint). I cannot for the life of me figure out why it's crashing. I have checked the connections for the File Owner and the outlets and cannot see anything wrong. I've also checked the name of the XIB to make sure I didn't spell it wrong in the loadNibNamed method.

The only thing indicated in the debugger console is:

"libc++abi.dylib: terminating with uncaught exception of type NSException"

I turned OS_ACTIVITY_MODE off and then received more info in the debugger console:

Uncaught exception: Could not load NIB in bundle: 'NSBundle </var/containers/Bundle/Application/C377C361-A15B-467A-A6AA-F3DFBB5CC285/TestApp.app> (loaded)' with name 'BMSkipBreakButton'

And I also see...

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </var/containers/Bundle/Application/C377C361-A15B-467A-A6AA-F3DFBB5CC285/TestApp.app> (loaded)' with name 'BMSkipBreakButton''
*** First throw call stack:
(0x1ea3ca180 0x1e95a29f8 0x1ea2d43a0 0x2162edb60 0x2162ee9dc 0x1008f0fa8 0x1008f0e78 0x100919198 0x1009196a4 0x21608a224 0x21608a628 0x10085c244 0x10085b498 0x21608a224 0x21608a628 0x1008fe0dc 0x100891ccc 0x100890e10 0x1008aa434 0x1002d6f10 0x100289ad4 0x10256b6f4 0x10256cc78 0x10257a6fc 0x1ea35bb20 0x1ea356a58 0x1ea355fb4 0x1ec55779c 0x216633c38 0x1002bc190 0x1e9e198e0)
libc++abi.dylib: terminating with uncaught exception of type NSException

Can someone help?

Update:

I noticed that the XIB did not have a target membership. I added it, but it still crashes:

enter image description here

JFortYork
  • 137
  • 10
  • Is that the full error message in console, or there is more that would hold the key info? Like this output https://stackoverflow.com/questions/26442414/libcabi-dylib-terminating-with-uncaught-exception-of-type-nsexception-lldb seethe " *** Terminating app due to uncaught exception 'NSUnknownKeyException'" is the important one. – Larme Jul 21 '20 at 12:51
  • That's all I see. That error in the console and then the breakpoint moves to the AppDelegate and just says "Thread 1: SIGABRT" – JFortYork Jul 21 '20 at 12:52
  • See edited comment, usually, I mean usually, there is a " *** Terminating app due to uncaught exception 'NSUnknownKeyException'" where the diff with yours is the uppercase at "Terminating", and NSUnknownKeuException vs NSException just before yours. – Larme Jul 21 '20 at 12:53
  • @Larme I updated the post with some errors I found. I had to disable OS_ACTIVITY_MODE. – JFortYork Jul 21 '20 at 13:01
  • Much more useful info. Is your bundle in your target ? Select your xib, check on the right the inspector (https://stackoverflow.com/a/54886353/1801544) and is it checked for your app ? – Larme Jul 21 '20 at 13:09
  • @Larne Yes, so I found out that my XIB was not part of a target called "BMVidiPlayerResources". All the other XIBs in the project are part of that target. But, that doesn't seem to have helped... it crashes with the same error – JFortYork Jul 21 '20 at 13:11
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/218286/discussion-between-jfortyork-and-larme). – JFortYork Jul 21 '20 at 13:14
  • Is it then the SAME error message? Maybe a cache issue: clean, rerun, if not remove derived data, re run? – Larme Jul 21 '20 at 13:14
  • @Larne I removed derived data, restarted Xcode and let it index, did a clean & build and still the same error. Uncaught exception: Could not load NIB in bundle: 'NSBundle (loaded)' with name 'BMSkipBreakButton' – JFortYork Jul 21 '20 at 13:20

0 Answers0