Q:

-[UIRoundedRectButton setImage:]: unrecognized selector sent to instance

I am trying to set a UIImageView's image equal to a certain image:
- (IBAction)showCard:(id)sender {
    for (KCCardView *cardView in self.view.subviews) {
        for (KCCard *aCard in dealerHand) {
            cardView.image = aCard.cardImage;
        }
    }
}

But all that keeps happening is the app crashes and the following is logged to the console. I can't seem to find the bug.
-[UIRoundedRectButton setImage:]: unrecognized selector sent to instance

Thank you!
    (gdb) backtrace
#0  0x012deccc in objc_exception_throw ()
#1  0x01150f0d in -[NSObject doesNotRecognizeSelector:] ()
#2  0x010b5e2f in ___forwarding___ ()
#3  0x010b5c12 in __forwarding_prep_0___ ()
#4  0x011510e9 in -[NSObject performSelector:withObject:withObject:] ()
#5  0x000197fd in -[UIApplication sendAction:to:from:forEvent:] ()
#6  0x00019792 in -[UIApplication sendAction:toTarget:fromSender:forEvent:] ()
#7  0x000be2aa in -[UIControl sendAction:to:forEvent:] ()
#8  0x000be773 in -[UIControl(Internal) _sendActionsForEvents:withEvent:] ()
#9  0x000bda3e in -[UIControl touchesEnded:withEvent:] ()
#10 0x0003eb04 in -[UIWindow _sendTouchesForEvent:] ()
#11 0x0003ed2d in -[UIWindow sendEvent:] ()
#12 0x0002550c in -[UIApplication sendEvent:] ()
#13 0x00018d00 in _UIApplicationHandleEvent ()
#14 0x00deb7fe in PurpleEventCallback ()
#15 0x01123435 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
#16 0x01087d72 in __CFRunLoopDoSource1 ()
#17 0x0108665a in __CFRunLoopRun ()
#18 0x01085b04 in CFRunLoopRunSpecific ()
#19 0x01085a1b in CFRunLoopRunInMode ()
#20 0x00de9f67 in GSEventRunModal ()
#21 0x00dea02c in GSEventRun ()
#22 0x00016cf2 in UIApplicationMain ()
#23 0x00001ed8 in main (argc=1, argv=0xbfffed94) at /Users/Alec/Desktop/Blackjack/Blackjack/main.m:16
#24 0x00001e35 in start ()

A:

First of all, you should post the stack trace of the error so we can be sure the error is happening in that code.  You may need to set an exception breakpoint to get the stack trace where the error happened.
Second, the error message is telling you that you are sending the setImage: message to a UIRoundedRectButton object.  If the error is happening in the code you posted, then the problem is that cardView is a UIButton, not a UIImageView.  You are looping over all of the subviews of self.view.  So we know that at least one of those subviews is a UIButton, not a UIImageView.
Also, your nested loops look suspicious.  I suspect you are trying to do something like this:
- (IBAction)showCard:(id)sender {
    int i = 0;
    for (UIView *view in self.view.subviews) {
        if (![view isKindOfClass:[KCCardView class]])
            continue;
        KCCardView *cardView = (KCCardView *)view;
        cardView.image = [[dealerHand objectAtIndex:i++] cardImage];
    }
}

That's not really a great way to do it either, but it might work for you.  A better way would be to give your view controller a separate NSArray that contains references to just the KCCardView instances.

