从自定义类和UIViewController继承委托方法(Objective C) [英] Inherit delegate methods from custom class and UIViewController (Objective C)

查看:74
本文介绍了从自定义类和UIViewController继承委托方法(Objective C)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a main controller which implements methods from a custom class. Now in the main controller I want to add a table within an alert view for which I need to implement UITableView delegate methods. I want to implement something like below

开单击单击此处按钮,将显示一个警报视图,其中包含一个显示所有项目的表。

On Clicking the Click Here Button, an alert view is displayed which contains a table displaying all the items.

CustomController is定义如下

CustomController is defined like below

@interface CustomController:UIViewController

在.h文件中

@接口mainController:CustomController< CustomDelegateMethod>

在.m文件中

@interface mainController()

在.h文件中

@interface mainController:CustomController< CustomDelegateMethod>

//我想添加 U. IViewController< UITableViewDelegate,UITableViewDataSource> 到上面一行。

// I want to add UIViewController<UITableViewDelegate, UITableViewDataSource> to the above line.

MainController中的AlertView代码:

AlertView code in MainController:

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>
它会抛出错误预期的标识符或'('
如果我添加tableview委托方法,如
@interface mainController:CustomController< CustomDelegateMethod, UITableViewDelegate,UITableViewDataSource> ,在运行应用程序时不调用委托方法。

How can I implement delegate methods from different controllers? Because When I add @interface mainController : CustomController<CustomDelegateMethod>,UIViewController<UITableViewDelegate, UITableViewDataSource> it is throwing an error Expected identifier or '(' and if I add the tableview delegate methods like this @interface mainController : CustomController<CustomDelegateMethod,UITableViewDelegate, UITableViewDataSource> , delegate methods are not called when I run the application.

推荐答案

尝试:

在.h文件中

@interface mainController : CustomController

.m文件中的

in .m file

@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];

这篇关于从自定义类和UIViewController继承委托方法(Objective C)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆