Setting a property on a custom object through Interface Builder

I have a custom subclass of UITableViewController that I use in two places in the nib file. What should I do if I want two instances to have slightly different behavior? Of course, in the code I can choose one type of behavior or another based on the BOOL value, but how to install BOOL from Interface Builder without having to write the Interface Builder plugin?

+3
source share
5 answers

As with Xcode 6, this is a new way. Now you can give the view properties the IBInspectable attribute, and then you can edit these properties in IB, as in the standard view.

So for example:

@property (nonatomic, strong) IBInspectable BOOL

( IBDesignable) : https://developer.apple.com/library/ios/recipes/xcode_help-IB_objects_media/chapters/CreatingaLiveViewofaCustomObject.html

+7

" " - , , , . Xcode 4.2.

, Apple Developer (?). .

+3

, IB IB.

, .

, BOOL, , , MyCustomViewController :

customViewController = [[MyCustomViewController alloc]initWithNibName:@"CustomViewController" bundle:nil];
[customViewController setFunky:YES];

- MyCustomViewDelegate. , :

@class MyCustomViewController;

@protocol MyCustomViewDelegate
@required
-(BOOL)customViewShouldBeFunky:(MyCustomViewController*)customView;
@end

@interface MyCustomViewController : UIViewController {
  NSObject<MyCustomViewDelegate>  *delegate;
}
@property (readwrite, retain) IBOutlet NSObject<MyCustomViewDelegate> *delegate;
@end

IBOutlet, , Interface Builder.

[delegate customViewShouldBeFunky:self], , .

+2

, , .

0

Here is an example of overriding properties and setting them in custom classes, this may help. The property code will work until awakeFromNib is called. This way you can decide what you need to do depending on the user rights in awakeFromNib.

fooobar.com/questions/1715453 / ...

0
source

Source: https://habr.com/ru/post/1715452/


All Articles