Quote:
Originally Posted by DevTeamOfOne
Yes, Dev has been a very helpful non-existent smilie-face and now we should all pay homage. GROUP HUG!
|
A huge hug for you
As the post title says, great thread DevTeamOfOne, it has been of great help for me... thanks to it I've been able to do in a couple of days more than I acheived struggling with IB over the lasts weeks.
Following your model I've been able to create my tabBar/NavBarController/tableView interface programatically and it's super-easy.
I'd like to ask you for a little guidance which I'm sure will help others as well.
I don't know if this is the right way of doing things but here it goes:
I'm creating a class from UIViewController for each of my table views inside the navigation controllers. As I said, I'm creating everything programatically instead of using IB as it seems easier (everything except the window which I haven't managed to get right, only a black window appears).
By now, I'm using the "-(id)initWithNibName

NSString *)nibNameOrNil bundle

NSBundle *)nibBundleOrNil" method on my class just to set its title (self.title = @"My Title"

so it shows in the NavBar from the beggining instead that after the view is loaded; also, on the loadView method I'm creating an UITableView and assigning it as the view for my Class. Finally, on the dealloc method of my class I'm releasing its tableView.
I'm implementing the UITableViewDataSource and UITableViewDelegate protocols so I also defined the numberOfRowsInSection and methods; by now, I just want to display static data.
What I described before I'm doing it the following way:
Code:
- (void)loadView {
UITableView *tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain];
tableView.autoresizingMask = (UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight);
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
tableView.delegate = self;
self.myTableView = tableView;
self.view = tableView;
[tableView release];
}
- (NSInteger)tableView:(UITableView *)myTableView numberOfRowsInSection:(NSInteger)section {
// just a static number by now
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)myTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [self.myTableView dequeueReusableCellWithIdentifier:@"myCell"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"myCell"] autorelease];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.text = [[NSString alloc] initWithFormat:@"Cell : %i", indexPath.row];
return cell;
}
However... my table is just showing blank, I don't know really what I'm missing so any help to get this table to show (by now) just a couple of cells with static data would be greatly appreciated.
Best regards.