我有水平滾動按鈕,將導航到另一個視圖控制器時,用戶選擇的按鈕,工作正常,但問題出現時,用戶輕按按鈕,導航欄已被隱藏。導航欄重疊水平滾動視圖
它看起來像水平滾動按鈕重疊導航欄。我已經編寫了這些滾動按鈕。
我有水平滾動按鈕,將導航到另一個視圖控制器時,用戶選擇的按鈕,工作正常,但問題出現時,用戶輕按按鈕,導航欄已被隱藏。導航欄重疊水平滾動視圖
它看起來像水平滾動按鈕重疊導航欄。我已經編寫了這些滾動按鈕。
後臺按鈕操作很可能是錯誤的。如上所述,我需要看到更多的代碼才能真正幫助。
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:@ 「主」 束:無] instantiateViewControllerWithIdentifier: @ 「AddInfoVC」]; [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)發送方{
UIStoryboard * storyboardObj = [UIStoryboard storyboardWithName:@ 「主」 束:無];
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
哪裏按鈕添加?到哪個視圖。 –
您需要提供更多信息,相關代碼,可能的截圖。嘗試閱讀你的問題,就好像你不知道你的問題。 – user5226582
@MartinBorstrand - 按鈕被添加到導航欄正下方的homeVC。它可以水平滾動。 – Jonathan