目标C UIViewController委托

强尼

我有一个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。不知道我做错了什么,所以需要换新的眼睛。

穆罕默德·迪亚·埃尔丁(Mohamed DiaaEldin)

创建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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

UIAlertController实用工具类无法调用UITextField委托或目标,但可以在UIViewController中使用

使用委托创建 UIViewController

如何使用目标C实现Apple Watch Crown委托

协议要求委托从UIViewController继承

SwiftUI 在 UIViewController 中调用委托

如何使用目标c停止和启动应用程序委托计时器?

在 App 委托 swift 中获取 UIVIewController 的名称

在UIView / UIViewController关系中定义委托

UINavigationController中的UIViewController不调用委托方法

长按时,如何从目标 c 函数而不是 contextMenuInteraction 函数调用 ImagePreviewController: UIViewController ?

uiviewcontroller解除分配时如何在目标c中触发阻止事件

没有目标的.net委托比目标慢

是否可以从同一项目的Swift类调用目标C应用程序委托方法?

为什么我在实现委托以将值从子 swift 类传递到父目标 C 类时出错?

C#:EventHandler 委托

什么是C ++委托?

委托Objective-C

C#委托与EventHandler

C# 委托与反射

C ++泛化委托

C++ 中的委托

目标C-如何从另一个类(另一个UIViewController)更改图像

从UIViewController返回NSString而不委托iOS7

扩展UIViewController以访问应用程序委托是反模式吗?

使用委托和协议在2个UIViewController之间传递数据

使用委托将数据从UIView子类发送到UIViewController

当不委托UIViewController时不调用UIImagePickerControllerDelegate方法

具有ContainerView的UIViewController的自定义委托

UIView和UIViewController之间的委托/协议不起作用