【问题标题】:Navigation bar is overlap by horizontal scrollview导航栏与水平滚动视图重叠
【发布时间】:2017-10-18 08:34:17
【问题描述】:

我有水平滚动按钮,当用户选择工作正常的按钮时,它将导航到另一个视图控制器,但是当用户点击返回按钮时出现问题,导航栏被隐藏。

看起来水平滚动按钮与导航栏重叠。我以编程方式编写了这些滚动按钮。

【问题讨论】:

  • 添加的按钮在哪里?到哪个视图。
  • 您需要提供更多信息、相关代码,可能还有截图。试着阅读你的问题,就好像你不知道你的问题一样。
  • @MartinBorstrand - 按钮被添加到导航栏下方的 homeVC 中。它可以水平滚动。
  • 需要更多信息,否则很难提供任何解决方案。
  • 您必须向我们展示您的代码,否则这是不可能的。

标签: ios objective-c uinavigationbar


【解决方案1】:

后退按钮操作可能执行错误。如上所述,我需要查看更多代码才能真正提供帮助。

【讨论】:

    【解决方案2】:
    HomeVC.h
    
    
    #import <UIKit/UIKit.h>
    
    
    @interface HomeVC : 
      UIViewController<UITableViewDelegate,UITableViewDataSource>
    - (IBAction)buttonClicked1:(id)sender;
    
    - (IBAction)buttonClicked2:(id)sender;
    
    -(IBAction)unWindHomeVC:(UIStoryboardSegue *) segue;
    
    -(void) imageTaped;
    
    - (IBAction)myProflBtn:(id)sender;
    
    - (IBAction)myContactBtn:(id)sender;
    
    
    @property (strong, nonatomic) IBOutlet UITableView *tablezView1;
    
    @property (strong, nonatomic) IBOutlet UITableView *tableView2;
    
    @property (strong, nonatomic) NSArray *devices;
    
    @end
    

    HomeVC.m

    #import "HomeVC.h"
    #import "AddInfoVC.h"
    #import "MyProfileTableViewCell.h"
    #import "SuperObject.h"
    #import "AppDelegate.h"
    
    
    
    
    
    
    @interface HomeVC ()
    
    
    
    {
    
    NSManagedObjectContext *context;
    
    NSIndexPath *selectIndexPath;
    
    
    }
    
    @end
    
    int j;
    
    @implementation HomeVC
    
    
    @synthesize tablezView1;
    @synthesize tableView2;
    @synthesize devices;
    
    
    
    
    - (void)viewDidLoad
    {
    
    
    [super viewDidLoad];
    
    
    AppDelegate *app = (AppDelegate *) [UIApplication 
    sharedApplication].delegate;
    
    context = app.persistentContainer.viewContext;
    
    
    
    
    }
    
    
    
    
    -(void) viewWillAppear:(BOOL)animated {
    
    
    NSMutableArray *arrImage = [NSMutableArray 
    arrayWithObjects:@"Recovery.png", 
    @"Fire.png",@"police.png",@"Hospital1.png",@"blood.png",nil];
    
    
    UIScrollView *scrollView = [[UIScrollView alloc] 
    initWithFrame:CGRectMake(0,60, self.view.frame.size.width, 100)];
    
    
    
    
    int x = 0;
    CGRect frame;
    for (int i = 0; i < 5; i++) {
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
        if (i == 0) {
            frame = CGRectMake(10, 25, 45, 45);
        } else {
            frame = CGRectMake((i * 80) + (i * 20) + 10, 25, 45, 45);
        }
    
        button.frame = frame;
        button.tag=i;
    
        NSString *butimage=arrImage[i];
    
        UIImage *buttonImage = [UIImage imageNamed:butimage];
    
        [button setBackgroundImage:buttonImage forState:UIControlStateNormal];
    
        NSLog(@"%ld",(long)button.tag);
    
        [button setBackgroundColor:[UIColor whiteColor]];
    
        [button addTarget:self action:@selector(imageTapped:) forControlEvents:UIControlEventTouchUpInside];
    
        [scrollView addSubview:button];
    
        if (i == 4)
        {
    
            x = CGRectGetMaxX(button.frame);
        }
    
    }
    
    scrollView.contentSize = CGSizeMake(x, scrollView.frame.size.height);
    
    scrollView.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:scrollView];
    

    }

    -(void) viewDidAppear:(BOOL)animated{
    
    [super viewDidAppear:animated];
    
    
    
    NSFetchRequest *fetch = [[NSFetchRequest alloc] initWithEntityName:@"Opositive"];
    
    devices = [context executeFetchRequest:fetch error:nil];
    
    [tablezView1 reloadData];
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    }
    
    
    
    
    -(void)imageTapped:(id)sender
    {
    UIButton *button = (UIButton *) sender;
    
    NSLog(@"tapped!");
    NSLog(@"%ld",(long)button.tag);
    
    switch(button.tag)
    {
        case 0 :
        {
            NSString * storyboardName = @"Main";
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
            UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"RecoveryVC"];
            [self presentViewController:vc animated:YES completion:nil];
    
        }
            break;
        case 1 :{
    
    
            NSString * storyboardName = @"Main";
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
            UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"FireServiceVC"];
            [self presentViewController:vc animated:YES completion:nil];
        }
            break;
        case 2 :
        {
            NSString * storyboardName = @"Main";
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
            UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"PoliceStationVC"];
            [self presentViewController:vc animated:YES completion:nil];
        }
    
            break;
        case 3 :
        {
            NSString * storyboardName = @"Main";
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
            UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"HospitalVC"];
            [self presentViewController:vc animated:YES completion:nil];
    
        }break;
        case 4 :
        {
            NSString * storyboardName = @"Main";
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
            UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"BloodDonationVC"];
            [self presentViewController:vc animated:YES completion:nil];
    
        } break;
    

    }

    }

    - (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    }
    
    
    -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    if(tableView == self.tablezView1){
    
        return devices.count;
    
    }
    else if (tableView == self.tableView2){
    
        return 5;
    }
    return 0;
    

    }

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    

    {

    if (tableView == self.tablezView1){
    
    
        static NSString *cellIdentifier1 = @"MyProfileTVCell";
    
        MyProfileTableViewCell *cell1 = (MyProfileTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier1];
    
        if (cell1 == nil){
    
        NSArray *nib1 =[[NSBundle mainBundle] loadNibNamed:@"MyProfileTableViewCell" owner:self options:nil];
    
            cell1 = [nib1 objectAtIndex:0];
    
        }
    
    
    
    
    
    
        NSManagedObject *mangedObj = [devices objectAtIndex:indexPath.row];
    
    
        cell1.prfNmeLbel.text = [NSString stringWithFormat:@"Profilename:%@",[mangedObj valueForKey:@"opositivename"]];
    
    
    
        cell1.prfCntLbel.text = [NSString stringWithFormat:@"ProfileContactNo:%@", [mangedObj valueForKey:@"opositivecontactno"]];
    
    
        cell1.prfCtyLbel.text = [NSString stringWithFormat:@"ProfileCity:%@", [mangedObj valueForKey:@"opositivecity"]];
    
    
    
        cell1.prfAddresLbl.text = [NSString stringWithFormat:@"ProfileAddress:%@", [mangedObj valueForKey:@"opositivecaddress"]];
    
    
    
        cell1.prfCountryLbl.text = [NSString stringWithFormat:@"ProfileCountry:%@", [mangedObj valueForKey:@"opositivecountry"]];
    
    
    
    
    
    
    
    
    
        return cell1;
    
    
    }
    
    if (tableView == self.tableView2){
    
        static NSString *cellIdentifier2 = @"CommonTVC";
    
        CommonTVC *cell2 = (CommonTVC *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier2];
    
        if (cell2 == nil){
    
            NSArray *nib2 = [[NSBundle mainBundle] loadNibNamed:@"CommonTVC" owner:self options:nil];
            cell2 = [nib2 objectAtIndex:0];
        }
        return cell2;
    }
    
    
    return 0;
    

    }

    -(BOOL) tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    if (indexPath.row %2 == 0){
    
    
        return YES;
    
    }
    
    
    return NO;
    

    }

    - (IBAction)addInfoButton:(id)sender {
    

    AddInfoVC *DishItemList=[[UIStoryboard storyboardWithName:@"Main" bundle:nil]instantiateViewControllerWithIdentifier:@"AddInfoVC"]; [self.navigationController pushViewController:DishItemList 动画:YES]; }

    - (IBAction)buttonClicked1:(id)sender {
    
    UIStoryboard *storyboardObj = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    
    AddInfoVC *addInfoObj = [storyboardObj instantiateViewControllerWithIdentifier:@"AddInfoVC"];
    
    [self presentViewController:addInfoObj animated:NO completion:nil];
    
    
    
    
    
    
    
    
    
    
    }
    
    • (IBAction)buttonClicked2:(id)sender {

      UIStoryboard *storyboardObj = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

      OptionVC *optObj = [storyboardObj instantiateViewControllerWithIdentifier:@"OptionVC"];

      [self presentViewController:optObj animated:NO completion:nil];

    }

    - (IBAction)unWindHomeVC:(UIStoryboardSegue *)segue{
    
    
    HomeVC *sourceVC = segue.sourceViewController;
    
    if([sourceVC isKindOfClass:[AddInfoVC class]]){
    
    
    
        NSLog(@"Coming from AddInfo");
    
    }
    
    
     if([sourceVC isKindOfClass:[ProfileVC class]]) {
    
         NSLog(@"Coming from ProfileVC");
    }
    
    
    if ([sourceVC isKindOfClass:[MyContactsVC class]]){
    
        NSLog(@"Coming from MyContacts");
    }
    

    }

    - (IBAction)myProflBtn:(id)sender {
    
    
    NSString *storyboardName = @"Main";
    
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
        ProfileVC *profile = [storyboard instantiateViewControllerWithIdentifier:@"ProfileVC"];
    
        profile.modalPresentationStyle = UIModalPresentationPopover;
    
        [self presentViewController:profile animated:YES completion:nil];
    
    
        // configure the popover presentation controller
    
        UIPopoverPresentationController *popController = [profile popoverPresentationController];
        popController.permittedArrowDirections = UIPopoverArrowDirectionAny;
    
         popController.delegate = self;
    
    
        popController.sourceView = self.view;
        popController.sourceRect = CGRectMake(30, 50, 10, 10);
    
    
    
    
    }
    
    
    
    
    - (IBAction)myContactBtn:(id)sender {
    
    
        NSString *storyboardName = @"Main";
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
        MyContactsVC *contact = [storyboard instantiateViewControllerWithIdentifier:@"MyContactsVC"];
    
        contact.modalPresentationStyle = UIModalPresentationPopover;
        [self presentViewController:contact animated:YES completion:nil];
    
        // configure the popover presentation controller
    
        UIPopoverPresentationController *popController = [contact popoverPresentationController];
        popController.permittedArrowDirections = UIPopoverArrowDirectionUp;
        popController.delegate = self;
    
        // In case we don't have a  bar button as reference
    
        popController.sourceView = self.view;
        popController.sourceRect = CGRectMake(30, 50, 10, 10);
    
    
    
    
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    @end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-09
      • 1970-01-01
      • 2016-02-08
      • 2017-02-08
      • 2014-06-25
      • 1970-01-01
      • 2021-05-31
      • 1970-01-01
      相关资源
      最近更新 更多