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":" toke开发者_StackOverflow社区n
any clue what I am doing wrong
regards
Use
[myViewController.view addSubview:newViewButton];
@selector(viewButton:sender)
should read @selector(viewButton:sender:)
精彩评论