Note that there are some explanatory texts on larger screens.

plurals
  1. POClassical MVC in Cocoa
    primarykey
    data
    text
    <p>I'm trying to structure some view-code out of the controller (obviously without using a nib). Therefore, I tried a simple example, but for some reason, I can't add the target to the button in the controller, rest is fine. Here's what I'm trying:</p> <p>Controller.h:</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import "IndexView.h" @interface IndexController : UIViewController { } @property (nonatomic) IndexView *contentView; @end </code></pre> <p>Controller.m</p> <pre><code>#import "IndexController.h" #import "IndexView.h" @interface IndexController () @end @implementation IndexController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { self.contentView = [[IndexView alloc]init]; [self.view addSubview:self.contentView]; [self connectUIElements]; } return self; } - (void) connectUIElements { [self.contentView.testButton addTarget:self action:@selector(testButtonClicked) forControlEvents:UIControlEventTouchUpInside]; } #pragma mark -- #pragma mark UIHandler - (void) testButtonClicked { NSLog(@"testbutton clicked"); } @end </code></pre> <p>View.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface IndexView : UIView @property (nonatomic, strong) UIButton *testButton; @end </code></pre> <p>View.m</p> <pre><code>#import "IndexView.h" @implementation IndexView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self setUpView]; } return self; } - (id) init { self = [super init]; if (self) { [self setUpView]; } return self; } - (void) setUpView { [self setBackgroundColor:[UIColor whiteColor]]; self.testButton = [[UIButton alloc]initWithFrame:CGRectMake(10, 50, 100, 50)]; self.testButton.backgroundColor = [UIColor greenColor]; [self.testButton setTitle:@"hello, world" forState:UIControlStateNormal]; [self addSubview:self.testButton]; } @end </code></pre> <p>I'm just exploring possibilities to get closer to a classical MVC pattern and a little farther away from Apples mediator-interpretation. Any idea what's wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload