繁体   English   中英

从自定义类和UIViewController继承委托方法(目标C)

[英]Inherit delegate methods from custom class and UIViewController (Objective C)

我有一个主控制器,它实现自定义类中的方法。 现在,在主控制器中,我想在警报视图中添加一个表,为此我需要实现UITableView委托方法。 我想实现如下

在此处输入图片说明

单击“ Click Here按钮后,将显示一个警报视图,其中包含一个显示所有项目的表格。

CustomController的定义如下

@interface CustomController : UIViewController

当下

在.h文件中

@interface mainController : CustomController<CustomDelegateMethod>

在.m文件中

@interface mainController()

需要

在.h文件中

@interface mainController : CustomController<CustomDelegateMethod>

//我想将UIViewController<UITableViewDelegate, UITableViewDataSource>到上面的行。

MainController中的AlertView代码:

UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"List of Items" message:nil delegate:self cancelButtonTitle:@"Back" otherButtonTitles:@"Add New Item", nil];

    tableView = [([UITableView alloc])initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.backgroundColor = [UIColor clearColor];
    [av addSubview:tableView];
    [av show];

如何实现来自不同控制器的委托方法? 因为当我添加@interface mainController : CustomController<CustomDelegateMethod>,UIViewController<UITableViewDelegate, UITableViewDataSource>它抛出了错误的Expected identifier or '('并且如果我添加了像这样的@interface mainController : CustomController<CustomDelegateMethod,UITableViewDelegate, UITableViewDataSource>委托方法@interface mainController : CustomController<CustomDelegateMethod,UITableViewDelegate, UITableViewDataSource>在运行应用程序时,不会调用@interface mainController : CustomController<CustomDelegateMethod,UITableViewDelegate, UITableViewDataSource>委托方法。

尝试:

在.h文件中

@interface mainController : CustomController

在.m文件中

@interface mainController() <CustomDelegateMethod,UITableViewDelegate, UITableViewDataSource>

@property(nonatomic,strong)UITableView * tableView;

@end

UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"List of Items" message:nil delegate:self cancelButtonTitle:@"Back" otherButtonTitles:@"Add New Item", nil];

UITableView *tableView = [([UITableView alloc])initWithFrame:CGRectZero style:UITableViewStyleGrouped];
tableView.delegate = self;
tableView.dataSource = self;
tableView.backgroundColor = [UIColor clearColor];
self.tableView = tableView;
[av addSubview:tableView];
[av show];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM