我有一个UIViewController,向其中添加了标签,按钮,tableView和searchView。我locationTableView
在系统中称其为
然后mapTabBarController
,我调用了另一个viewController ,当用户单击按钮时,我将其称为代码
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[self.navigationController setNavigationBarHidden:YES];
locationTableView = [self.storyboard instantiateViewControllerWithIdentifier:@"LocationTableViewController"];
[self.view addSubview:locationTableView.view];
我禁用了status bar
和,navigation bar
因为它location view
是屏幕上的直接叠加层,但仍显示mapTabBar
我目前正在使用“取消”按钮,它实际上只是隐藏了,locationTableView
然后将导航栏和状态栏重新显示。我最初试图使此功能正常运行
- (IBAction)cancelButtonPressed:(id)sender {
[[UIApplication sharedApplication] setStatusBarHidden: NO];
[self.view removeFomSuperview];
}
这行得通,但后来我不知道如何重新显示NavigationBar。因此,我想到了创建一个代表来做到这一点,因此我开始着手这一工作:
LocationTableViewController.h
#import <UIKit/UIKit.h>
@class LocationTableViewController;
@protocol LocationTableViewControllerDelegate;
@interface LocationTableViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITableView *locationTableView;
- (IBAction)cancelButtonPressed:(id) sender;
@property (strong, nonatomic) id<LocationTableViewControllerDelegate>delegate;
@end
@protocol LocationTableViewControllerDelegate <NSObject>
- (void) LocationTableViewcontroller:(LocationTableViewController *)viewController cancelButtonPressed:(CGFloat)value;
@end
LocationTableViewController.m
#import "LocationTableViewController.h"
@interface LocationTableViewController ()
{
UISearchBar *searchBar;
}
@end
@implementation LocationTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self navigationController].delegate = self;
searchBar = [UISearchBar new];
[searchBar setFrame: CGRectMake(8, 0, [[UIScreen mainScreen]bounds].size.width, 50)];
[searchBar setTranslatesAutoresizingMaskIntoConstraints:YES];
[self.locationTableView addSubview:searchBar];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
- (IBAction)cancelButtonPressed:(id)sender {
id<LocationTableViewControllerDelegate> strongDelegate = self.delegate;
[strongDelegate LocationTableViewcontroller:self cancelButtonPressed:0.0f];
}
@end
然后在我的MapTabBarController.m中实例化它
@interface MapTabBarController () <FPPopoverControllerDelegate, PrivacyPopoverDelegate, UITabBarControllerDelegate, LocationTableViewControllerDelegate>
@end
我为此创建了函数:
- (void)LocationTableViewcontroller:(LocationTableViewController *)viewController cancelButtonPressed:(CGFloat)value {
NSLog(@"We Clicked the Cancel Button!");
}
我遇到的问题是,它从未被调用-控制台中没有NSLog。不知道我做错了什么,所以需要换新的眼睛。
创建locationTableView时应该做什么
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[self.navigationController setNavigationBarHidden:YES];
locationTableView = [self.storyboard instantiateViewControllerWithIdentifier:@"LocationTableViewController"];
[self.view addSubview:locationTableView.view];
// Add this line
locationTableView.delegate = mapTabBarController
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句