首页 文章

基于UITabBar的生命周期中的UIViewController

提问于
浏览
0

我已经为每个标签添加了一个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 回答

  • 1

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

  • 0

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

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

相关问题