简体   繁体   中英

Bottom toolbar buttons flashes for a second?

this little issue is really getting on me.

I have hierarchal navigation controller: RootView-->2ndListView-->DetailView

I implemented bottom toolbar with buttons easily on the DetailView. Works perfectly there.

However, in the 2ndListView, when I follow the same thing and put the following code in either viewdidload or viewwillappear or any other similar method, the button just flashes for a second when the view loads, and then hides.

Instead, if I put up this code in cellForRowAtPathIndex (so that nothing is executed after that), it does work. But this is obviously very inefficient.

So there is something happening in between. What could be the issue?

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 (也许在viewDidDisappear调用中),则在新的视图控制器对其进行设置后,这些项目将消失。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM