I've set a UITabBr based app with many UIViewControllers for each tab that I added (5) Now I've had problems with adding a TableView for each tab as i pointed here UITableView in each tab but nobody had a solution so I thought about it and tried many ways the point now is: which method is called at first in the UIViewController when user touches a tab ? (viewDidLoad and viewWillAppear didn't work)
there is a specific lifecycle ?
here's the normal code, nothing is displayed in the console when you click on the tab
#
import "MusicView.h"
@implementation MusicView
@synthesize tv;
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 10;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
//cell.textLabel.text = [elements objectAtIndex:indexPath.row];
开发者_JAVA百科 return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
NSLog(@"initWithNibName works");
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSLog(@"viewDidLoad works");
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
thanks
Have you set yourself as the datasource and delegate as well as subclassed UITableViewController and subscribed to the datasource and delegate protocols in your individual tab view controllers?
There is too much information you haven't provided.
We do not know what subclass it is from, and we do not know anything about the delegate / datasource methods.
Please follow this tutorial - http://www.youtube.com/watch?v=LBnPfAtswgw
精彩评论