views:

48

answers:

2

Hi, 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

+3  A: 

Use

[myViewController.view addSubview:newViewButton];
Ole Begemann
Hi Ole, actually I mistyped my cry for help (just updated it). This is how I've got it and where I get the error as above ...
iFloh
it seems the "myViewController.view" reference causes the error. An NSLog reveals error "accessing unknown 'view' class method". Don't understand this since myViewController is of type UIViewController.
iFloh
ok, found the problem ... stupid ... passed the class, not the object ....
iFloh
+2  A: 

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

Cheers, Markus

frenetisch applaudierend