Iphone 底部工具栏按钮闪烁一秒钟?
这个小问题真让我恼火 我有分层导航控制器:RootView-->2ndListView-->DetailView 我在DetailView上实现了带有按钮的底部工具栏。在那里工作得很好 但是,在第二个ListView中,当我按照相同的方法将以下代码放入viewdidload或ViewWillDisplay或任何其他类似方法中时,当视图加载时,按钮只闪烁一秒钟,然后隐藏 相反,如果我把这段代码放在cellForRowAtPathIndex中(这样之后就不会执行任何操作),它确实可以工作。但这显然是非常低效的 所以在这两者之间发生了一些事情。 可能是什么问题Iphone 底部工具栏按钮闪烁一秒钟?,iphone,uinavigationcontroller,toolbar,Iphone,Uinavigationcontroller,Toolbar,这个小问题真让我恼火 我有分层导航控制器:RootView-->2ndListView-->DetailView 我在DetailView上实现了带有按钮的底部工具栏。在那里工作得很好 但是,在第二个ListView中,当我按照相同的方法将以下代码放入viewdidload或ViewWillDisplay或任何其他类似方法中时,当视图加载时,按钮只闪烁一秒钟,然后隐藏 相反,如果我把这段代码放在cellForRowAtPathIndex中(这样之后就不会执行任何操作),它确实可以工作。但这显然是
NSMutableArray *array;
NSMutableArray *tags;
@implementation SMSListViewController
@synthesize smses,catID,addButtonItem,filteredSMS,searchBar,searchController;
-(void)getStarted{
array = [[NSMutableArray alloc] init];
tags = [[NSMutableArray alloc] init];
SMSDBAccess *smsDBAccess = [[SMSDBAccess alloc] init];
smsDBAccess.catID = self.catID;
self.smses = [smsDBAccess getAllItems];
[smsDBAccess closeDatabase];
[smsDBAccess release];
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc {
[array release];
[smses release];
[super dealloc];
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
[self.navigationController setToolbarHidden:NO];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
UIBarButtonItem *addSMSButoon = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(addSMS:)];
UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
NSArray *buttons = [NSArray arrayWithObjects:space,addSMSButoon, nil];
[self.navigationController.toolbar setItems:buttons animated:NO];
[addSMSButoon release];
[space release];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self getStarted];
[self.tableView reloadData];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [smses count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
SMS *aSMS = [self.smses objectAtIndex:indexPath.row];
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text =aSMS.sms;
cell.detailTextLabel.text=aSMS.sms;
return cell;
}
@end
navigationController
在您的整个导航堆栈之间共享,因此如果在某个位置将navigationController
的项设置为nil
(可能在视图调用中)在新的视图控制器设置后,这将导致项目消失。感谢您的回复。。。但在RootView中并没有和工具栏相关的代码,并且DetailView在那个时并没有被执行。顺便说一句,让我知道我是否应该粘贴更多的代码来帮助您找到问题。也许在IB中?也许您可以尝试在navigationController工具栏项上设置keyValue观察者。然后,当它被设置为nil时,您将收到通知,您可以从那里了解它,我是一个初学者&尽管我试图理解它,但我无法使用keyValue Observer。相反,我对我的问题进行了编辑,将第二个列表.m包含在内。我刚刚粘贴了我认为与问题相关的代码。请看看这是否有帮助!不,代码没有帮助。我猜是有什么东西正在将项设置为nil,所以最好的做法是在调用它的任何地方,代码中的任何地方设置断点,然后查看触发时的值是什么,为什么调用它,以及从何处调用它。这将引导你走向自我发现的道路。嘿。。。谢谢虽然,我没有找到罪魁祸首,但在遵循您的建议的同时,我在viewDidLoad中发布了代码,它可以正常工作!!(我不知道如何标记你的评论有用)