user306766
user306766

Reputation:

Access a viewControllers View

I am trying to get to grips with programmatically configuring views. I have a UIViewController and want to add a UIButton to its view.

Well, I created the button:

UIButton *newViewButton = [[UIButton alloc] initWithFrame:CGRectMake(baseX + viewPlusX, baseY + viewPlusY, viewWidth, viewHeight)];
[newViewButton setTitle:@"View" forState:UIControlStateNormal];
[newViewButton setTag:(int)key];
[newViewButton addTarget:myViewController action:@selector(viewButton:) forControlEvents:UIControlEventTouchUpInside];

but when trying to add it to the view

[myViewController.view addSubview:newViewButton];

I get the error

error: expected ':' before":" token

any clue what I am doing wrong

regards

Upvotes: 1

Views: 105

Answers (2)

Alfonso
Alfonso

Reputation: 8492

@selector(viewButton:sender) should read @selector(viewButton:sender:)

Upvotes: 2

Ole Begemann
Ole Begemann

Reputation: 135578

Use

[myViewController.view addSubview:newViewButton];

Upvotes: 3

Related Questions