-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcontrolleractor.html
40 lines (38 loc) · 1.32 KB
/
controlleractor.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<h2>Good Controller Actor</h2>
<p>This feature is used for those who not use 'Inteface Builder' to create their views. It's solving problem, when you have many views and subviews, and some of your deep subview need reference of owner controller.
In short, controller reference for every view. Let's have some view <br/>
```objc
//SomeView.h
@interface SomeView : UIView {
}
//property with reference on controller, must be namend 'owningController'
@property(readonly) MyViewController *owningController;
@end
//SomeView.m
@implementation SomeView
@dynamic owningController;
@end
```
<br/>
And some Controller :<br/>
```objc
//MyViewController.h
@interface MyViewController : UIViewController {
}
@end
//MyViewController.m
@implementation MyViewController
- (void)viewDidLoad {
SomeView *customView = [[[SomeView alloc] init] autorelease];
[self.view addSubView:customView];
}
@end
```
<br/>
And now last step, add controller into container :<br/>
```objc
MVIOCControllerActor *goodControllerActor = [[[MVIOCControllerActor alloc] init] autorelease];
[[self.container actAs:goodControllerActor] addComponent:[MyViewController class]];
```
</p>
<p>After that all, everywhere in our views we can have readonly property marked as <code>@dynamic</code> named exactly 'owningController' which is filled with controller in which is that view showed</p>