基于UITabBar的生命周期中的UIViewController

时间:2011-06-17 18:09:41

标签: iphone objective-c uitableview uitabbarcontroller lifecycle

我已为我添加的每个标签设置了一个基于UITabBr的应用程序,其中包含许多UIViewControllers(5) 现在我遇到了为每个标签添加TableView的问题,正如我在此指出的那样UITableView in each tab 但没有人有解决方案,所以我想到了它并尝试了很多方法 现在的观点是:当用户触摸标签时,首先在UIViewController中调用哪个方法? (viewDidLoad和viewWillAppear不起作用)

有一个特定的生命周期吗?

这是正常代码,当您单击选项卡

时,控制台中不会显示任何内容
#

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];

    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

感谢

2 个答案:

答案 0 :(得分:1)

您是否已将自己设置为数据源和委托以及子类UITableViewController,并在各个选项卡视图控制器中订阅数据源和委托协议?

答案 1 :(得分:0)

There is too much information you haven't provided.我们不知道它是什么子类,我们对委托/数据源方法一无所知。

请遵循本教程 - http://www.youtube.com/watch?v=LBnPfAtswgw

相关问题