KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
In a seemingly never ending effort to learn more about iphone development, I have been playing around with some of the source code available through apples developer website. The particular example I am working with is Core Data Books, found here . The DetailViewController, and the AddViewController are made programatically, because there aren't any xib files for them. My question is about programatically adding things to a view without using IB. I want to put a UISwitch beneath the UITableView that has the detailed information about a particular book in the DetailView. How do I do this? This is what I have tried so far: In the AddViewController, I setup the UISwitch: @interface AddViewController : DetailViewController { id <AddViewControllerDelegate> delegate; UISwitch *onoff; } @property (nonatomic, assign) id <AddViewControllerDelegate> delegate; @property (nonatomic, retain) IBOutlet UISwitch *onoff; I also setup an IBAction: - (IBAction)flip:(id)sender; Then I synthesize it in the AddViewController.m file, but nothing happens. I just need to setup the switch and make it so that I can control what it does from my IBAction that I setup. I know this is embarrassingly simple, but I can't figure it out. So, any help would be appreciated! Thanks Edit 1 So I implemented the code as I was directed to in the viewDidLoad, like so: - (void)viewDidLoad { [super viewDidLoad]; UISwitch *onoff = [[UISwitch alloc] initWithFrame: CGRectZero]; [onoff addTarget: self action: @selector(flip:) forControlEvents:UIControlEventValueChanged]; // Set the desired frame location of onoff here [self.view addSubview: onoff]; And it throws two warnings saying that the local declaration of 'onoff' hides the instance variable. But even
Tags (comma-separated)
Save Edits
Cancel