inheritance自定义类和UIViewController的委托方法(Objective C)
我有一个主控制器,实现自定义类的方法。 现在在主控制器中,我想在alert视图中添加一个表,为此我需要实现UITableView委托方法。 我想实现像下面的东西
点击Click Here
button,会显示一个警报视图,其中包含一个显示所有项目的表格。
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 '('
,如果我添加tableview委托方法像这样@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];