简体   繁体   English

来自另一个类的任何对象委托

[英]any object delegate from another class

I want to ask one thing, let suppose I have one view controller which has table view button etc now i create NSObject class for table one NSObject class for button and place there delegates over there. 我想问一两件事,让假设我有具有表视图按钮等一个视图控制器现在我创建NSObject为表一类NSObject类按钮,并将有代表在那边。 Can I do this? 我可以这样做吗? If yes how? 如果是,怎么办?

Like I want to place table in "myviewcontroller" and i place tableview delegates in "mytable" nsobject class and call delegates from myviewcontroller class ? 就像我想将表放置在“ myviewcontroller”中,并将表视图委托放置在“ mytable” nsobject类中,并从myviewcontroller类调用委托吗?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

Just make your NSObject subclass delegate of UITableView and assign it to your tableView. 只需使UITableView的NSObject子类委托并将其分配给tableView即可。

myTableController = [MyTableController alloc] init];
myTableView = [UITableView alloc] initWithStyle...];
myTableView.delegate = myTableViewController;

I'm assuming that you have the access to both UITableView object (say mTable ) and UIButton object (say btn ) 我假设您可以同时访问UITableView对象(例如mTable )和UIButton对象(例如btn

in your viewDidLoad or any other method do like this 在您的viewDidLoad或任何其他方法中这样做

mTable.delegate = mytableObj;

[btn addTarget:mybutton action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];

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

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