导航栏通过水平滚动视图重叠

时间:2017-10-18 08:34:17

标签: ios objective-c uinavigationbar

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

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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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:@&#34; Main&#34;束:无] instantiateViewControllerWithIdentifier:@&#34; AddInfoVC&#34;];     [self.navigationController pushViewController:DishItemList animated: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:@&#34; Main&#34;束:无];

    OptionVC * optObj = [storyboardObj instantiateViewControllerWithIdentifier:@&#34; OptionVC&#34;];

    [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