开发者

iOS: assigning a class to a xib, and not recognizing it

开发者 https://www.devze.com 2023-03-04 18:07 出处:网络
I开发者_如何学Go\'m using the following code to load a xib in my UIView subclass named ImageWithCaptionView.

I开发者_如何学Go'm using the following code to load a xib in my UIView subclass named ImageWithCaptionView. I've specified in the xib Inspector the name of the view: ImageWithCaptionView.

However the if statement (isKindOfClass) is never true, and I've to remove it to make things work. What am I missing here ?

    UINib *nib = [[UINib nibWithNibName:NSStringFromClass([ImageWithCaptionView class]) bundle:nil] retain];

    NSArray *myArray = [nib instantiateWithOwner:self options:nil];  

     for (id currentObject in myArray) {
         if ([currentObject isKindOfClass:[ImageWithCaptionView class]]) {
             self = (ImageWithCaptionView *) currentObject;
             break;
        }
     }


Check if the class is also set in the Custom Class field in the identity inspector tab.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号