2017-10-18 4 views
-2

J'ai des boutons de défilement horizontal qui vont naviguer vers un autre contrôleur de vue lorsqu'un utilisateur sélectionne le bouton qui fonctionne bien mais le problème survient lorsque l'utilisateur tape sur le bouton, la barre de navigation est cachée.La barre de navigation se chevauche par scrollview horizontal

Il semble que les boutons de défilement horizontal chevauchent la barre de navigation. J'ai écrit ces boutons de défilement par programme.

+0

Où est les boutons étant ajoutés? Pour quelle vue. –

+1

Vous devez fournir plus d'informations, le code approprié, éventuellement des captures d'écran. Essayez de lire votre question comme si vous n'aviez aucune idée de votre problème. – user5226582

+0

@MartinBorstrand - Les boutons sont ajoutés à homeVC juste en dessous de la barre de navigation. il peut être défiler horizontalement. – Jonathan

Répondre

0

Il est probable que l'action du bouton de retour soit incorrecte. Comme mentionné ci-dessus, je devrais voir plus de code pour vraiment aider.

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: @ paquet "Main": nil] instantiateViewControllerWithIdentifier: @ "AddInfoVC"]; [self.navigationController pushViewController: DishItemList animé: OUI]; }

- (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: @ paquet "Main": nil];

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

    [self presentViewController: optObj animé: NO achèvement: néant];

}

- (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