[Dev] UITableView, if anyone can assist
I am trying to get a table to load. As we all know, I can't do it in IB - I've been making a basic interface in IB and then using (void)awakeFromNib to add elements to the interface that aren't part of IB. It sort-of works. I'm having two problems and would love some help, I've run into a wall for the past two days.
I'm (fairly) new to objective-c and i've been looking at all of the sample UITableView code but none of the examples implement a table view from a separate UIViewController class or from an awakefromnib method, so I can't figure out how to do it. What I mean is that they all implement a table with AppDelegate and a rootViewController. When I try to implement a table view like the examples, my app crashes, I think because I have a tab bar as the root view controller so I can't initWithRootViewController. I *think* but don't know that that's why my app crashes when i follow the examples.
I've been using this code in my awakeFromNib method in my view controller class that I'm trying to use:
UITableView *tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]
style:UITableViewStylePlain];
tableView.delegate = self;
tableView.dataSource = self;
tableView.rowHeight = 54;
[tableView reloadData];
It either doesn't show up or crashes the app (if i put it in my appdelegate file).
Anyway, can anyone explain how to implement a table in (void) awakeFromNib, or something similar, so i can add the table to the nib file through my code?
Secondly, when I try to do the same thing with say, a UISwitch or Slider or Button they remain static (even though I am sure I have my views set to be user interactable), why would they not respond to my actions? Here's an example of the code I've used for the UISwitch:
CGRect frame = CGRectMake(0, 0, 60, 26);
UISwitch *switchControl = [[UISwitch alloc] initWithFrame:frame];
[switchControl addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
[switchControl setBackgroundColor:[UIColor clearColor]];
[self.view addSubview: switchControl];
I would LOVE some assistance, I have this great user interface and the elements of what will be a cool program but I need a table view and some extra controls like I need air to breathe and this is driving me insane. Thanks in advance.