您的位置:首页 > 博客中心 > APP开发 >

iOS Programming Recipe 6: Creating a custom UIView using a Nib

时间:2022-03-15 17:52

iOS Programming Recipe 6: Creating a custom UIView using a Nib

JANUARY 7, 2013 BY MIKETT 12 COMMENTS gxlsystem.com,gxl网Mihai Damian says: January 9, 2013 at 3:11 pm

One potential drawback with of approach is that you cannot directly link IBOutlets from the Nib since you have no file owner for it. Of course you could grab the subviews by tags and assign them yourself but this is error prone since it’s much more difficult to keep track of tags. Alternatively you could create an extra “template” instance of CustomView, set it as the file owner and then do the manual IBOutlet assignment from the template instance to the actual instance that you’ll be returning. This has the advantage of explicitly naming the UIViews you’re working with but it feels a bit hackish and it takes the most effort to implement.

Reply
  • gxlsystem.com,gxl网Mike Turner says: January 9, 2013 at 5:07 pm

    Thanks for the comment!

    You can actually link up IBActions & IBOutlets, although it is slightly different than with a UIViewController. Using the example above add this property declaration to CustomView.h.

    //This will link to the label in CustomView.xib
     @property (nonatomic, strong) IBOutlet UILabel *label;

    Now in CustomView.xib, (control + drag) from the top level object (our CustomView object, where the property declaration lives, instead of file’s owner) to the UILabel. You should be presented with a HUD allowing you to select the “label” outlet just created!

    I’ll append the post to show this process.

    Reply

iOS Programming Recipe 6: Creating a custom UIView using a Nib,gxlsystem

相关推荐

电脑软件

本类排行

今日推荐

热门手游