基于 UITabBar 的生命周期中的 UIViewController
我已经为我添加的每个选项卡设置了一个基于 UITabBr 的应用程序,其中包含许多 UIViewControllers (5) 现在,我在为每个选项卡添加 TableView 时遇到了问题,正如我在这里指出的 每个选项卡中的 UITableView 但没有人有解决办法,所以我思考并尝试了很多方法 现在的重点是:当用户触摸选项卡时,首先在 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
谢谢
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];
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否将自己设置为数据源和委托以及子类 UITableViewController 并在各个选项卡视图控制器中订阅了数据源和委托协议?
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?
您没有提供太多信息。
我们不知道它来自哪个子类,也不知道有关委托/数据源方法的任何信息。请按照本教程操作 - http://www.youtube.com/watch?v=LBnPfAtswgw
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