I'm getting my feet wet with objective-C. And thought I'd play with iphone development. I have a Page Controller.h and .m
Inside my implementation file I've thrown a UIButton inside the viewDidLoad method.
- (void)viewDidLoad { [super viewDidLoad]; // content that loads in view UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; myButton.frame = CGRectMake(10, 160, 300, 44); [myButton setTitle:@"Press Me!" forState:UIControlStateNormal]; myButton.titleLabel.font = [UIFont systemFontOfSize:14]; // add to a view [self.view addSubview:myButton]; } So far it's showing fine. This makes me ask about the difference between loadView vs viewDidLoad.
Also, I want to run my own function when the button is pressed, but I constantly get an executable error from xcode.
Here's what I've interjected within the code above:
- (void)viewDidLoad { [super viewDidLoad]; // content that loads in view UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; myButton.frame = CGRectMake(10, 160, 300, 44); [myButton setTitle:@"Press Me!" forState:UIControlStateNormal]; myButton.titleLabel.font = [UIFont systemFontOfSize:14]; //added this [myButton addTarget:self action:@selector(runClick) forControlEvents:UIControlEventTouchUpInside]; // add to a view [self.view addSubview:myButton]; } -(void)runClick{ NSLog(@"does this work?"); } Does anything seem out of place to anyone?
Also, In the PageController.h I added: -(void)runClick;
Here's the Error I catch:
2012-03-17 16:04:30.077 Blah[510:207] -[__NSCFString runClick]: unrecognized selector sent to instance 0x6a0b4f0