Search code examples
xcodeios5iboutlet

XCode throws Sigabrt error whenever I run due to IBOutletCollection


I am creating an app for iOS 5 and I am getting the following error:

Assertion failure in -[UIRuntimeOutletCollectionConnection performConnect], /SourceCache/UIKit_Sim/UIKit-1912.3/UIRuntimeOutletCollectionConnection.m:43

I have tried to debug the error and can see that it occurs because I connect an item to an IBOutletCollection.

The IBOutletCollection is being defined as follows:

@property (strong) IBOutletCollection(BallButton) NSSet *Balls;

with

NSSet *Balls;

being defined as an instance variable.

Whenever I have not connected a Ball to the collection in interface builder the app will load fine. However, as soon as any of the balls are added to the collection then I will get an error after the ViewController and all the balls have been instantiated and before ViewDidLoad in the ViewController.

It was working fine and then I repositioned some of the layers and now I can't get rid of this error.

If anyone can help with even a suggestion of why this is happening or even just an iOS 5 example of using IBOutletCollection (in case I have done something wrong in the setup, but I don't think I have) then it would be much appreciated.

Thanks


Solution

  • Instead of using IBOutletCollection you can get the view that contains all the items you want in the collection and connect it using IBOutlet. Then use:

    - (NSSet *)getBallsFromView:(UIView *)view
    {
        NSMutableSet *balls = [[NSMutableSet alloc] init];
        for (UIView *subview in [view subviews]) 
        {
            if ([subview isKindOfClass:[BallButton class]])
                [balls addObject:(BallButton *)subview];
        }
    }
    

    This will retrieve all the items from the view that are of the specific type and then you can simply add them to the collection. This only gets all the items if they are directly on the view you are iterating through. If there a subviews that also contain items you want you will have to call this method recursively.