没有第一次没有显示右栏按钮项目

时间:2017-01-18 09:08:18

标签: ios objective-c uibarbuttonitem

This is first time, edit button visible. But when i come from another tab edit button not visible, but if i press there it will visible. 在我的UITableView我使用UINavigationBar中的rightBarButton编辑项。但它只是第一次出现。当我下次从另一个标签到达此标签时,它未显示。如果我按下那个按钮的位置就会显示出来。有什么问题?

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStylePlain target:self action:@selector(editActionOfTable) ];

-(void)editActionOfTable{


if (isEdited) {


    isSelctedAll = NO;
    [self.selectallButton setTitle:@"Select All" forState:UIControlStateNormal];

    self.navigationItem.rightBarButtonItem.title = @"Edit";
    //[self.editButton setTitle:@"Edit" forState:UIControlStateNormal];
    [self.tableView setEditing:NO animated:YES];
    [self customViewHide:YES];
    isEdited = NO;
    isDeleteButtonPress = false;


    self.navigationItem.hidesBackButton = NO;
    flagForCustomCell = false;


    NSDictionary *userInfo = [NSDictionary dictionaryWithObject:@"bottom" forKey:@"pos_Key"];
    [[NSNotificationCenter defaultCenter] postNotificationName: @"ad_banner" object:nil userInfo:userInfo];


}
else{


    NSDictionary *userInfo = [NSDictionary dictionaryWithObject:@"top_of_tab" forKey:@"pos_Key"];
    [[NSNotificationCenter defaultCenter] postNotificationName: @"ad_banner" object:nil userInfo:userInfo];


    flagForCustomCell = true;

    //disable delete button when array empty
    [self.deleteButtonOutlet setEnabled:NO];
    self.deleteButtonOutlet.alpha = 0.5;

    //disable fav button when array empty
    [self.favInHistoryOutlet setEnabled:NO];
    self.favInHistoryOutlet.alpha = 0.5;


    self.navigationItem.rightBarButtonItem.title = @"Done";
    //[self.editButton setTitle:@"Done" forState:UIControlStateNormal];

    [self customViewHide:NO];

    isDeleteButtonPress = true;
    [self.tableView setEditing:YES animated:YES];
    self.navigationItem.hidesBackButton = YES;


    isEdited = YES;


}


}

这是我的ViewWillAppear代码:

 -(void)viewWillAppear:(BOOL)animated{

self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];

NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"History"];


self.devices = [[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];
self.devices=[[[self.devices reverseObjectEnumerator] allObjects] mutableCopy];


NSFetchRequest *fetchRequest1 = [[NSFetchRequest alloc] initWithEntityName:@"Favourite"];

self.fvrt = [[managedObjectContext executeFetchRequest:fetchRequest1 error:nil] mutableCopy];
self.fvrt=[[[self.fvrt reverseObjectEnumerator] allObjects] mutableCopy];

[self setHeightForSpecificRow];

isDeleteButtonPress = false;

if(self.segmentControl.selectedSegmentIndex == 0){

    segment = self.devices.count;
    if(segment == 0){

        self.navigationItem.rightBarButtonItem.enabled = NO;

        self.tableView.hidden = YES;
        emptyView.hidden = NO;
        if(IS_DEVICE_IPAD){
            [noHistoryFavImage setImage:[UIImage imageNamed:@"no-history-ipad.png"]];
        }
        else{
            [noHistoryFavImage setImage:[UIImage imageNamed:@"no-history-iphone.png"]];
        }
        emptyViewLabel1.text = @"You do not have any translation history right now.";

    }
    else{

        self.navigationItem.rightBarButtonItem.enabled = YES;

        self.tableView.hidden = NO;
        emptyView.hidden = YES;
    }
}

else{
    segment = self.fvrt.count;

    if(segment == 0){

        self.navigationItem.rightBarButtonItem.enabled = NO;

        self.tableView.hidden = YES;
        emptyView.hidden = NO;

        if(IS_DEVICE_IPAD){
            [noHistoryFavImage setImage:[UIImage imageNamed:@"heart-ipad.png"]];

        }
        else{
            [noHistoryFavImage setImage:[UIImage imageNamed:@"heart-iphone.png"]];
        }
        emptyViewLabel1.text = @"You do not have any favorites right now.";
    }
    else{

        self.navigationItem.rightBarButtonItem.enabled = YES;

        self.tableView.hidden = NO;
        emptyView.hidden = YES;
    }
}



[self.tableView reloadData];
//self.navigationController.navigationBar.tintColor = [UIColor redColor];
   }

0 个答案:

没有答案