底部工具栏按钮闪烁一秒钟?

时间:2011-05-14 12:42:21

标签: iphone uinavigationcontroller toolbar

这个小问题真的让我感到高兴。

我有分层导航控制器:RootView - > 2ndListView - > DetailView

我在DetailView上轻松实现了带有按钮的底部工具栏。在那里完美运作。

然而,在2ndListView中,当我遵循相同的事情并将以下代码放入viewdidload或viewwillappear或任何其他类似的方法时,按钮只是在视图加载时闪烁一秒,然后隐藏。

相反,如果我在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

1 个答案:

答案 0 :(得分:0)

navigationController在您的整个导航堆栈之间共享,因此如果您将navigationController的项目设置为nil(可能在viewDidDisappear中调用)它会导致项目在被新视图控制器设置后消失。