繁体   English   中英

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

[英]Bottom toolbar buttons flashes for a second?

这个小问题真的困扰着我。

我有分层的导航控制器: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

navigationController在整个导航堆栈之间共享,因此,如果在某个地方将navigationController的项目设置为nil (也许在viewDidDisappear调用中),则在新的视图控制器对其进行设置后,这些项目将消失。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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