我有 ViewController_1 和 Button_1:
@interface ViewController_1 : UIViewController <UITableViewDataSource, UITableViewDelegate>
{
IBOutlet UIView *secondView;
UITableView *myTable;
}
- (IBAction)buttonPressed:(id)sender;
所有tableView委托(delegate)方法均在ViewController_1.m中实现
在 ViewController_1.xib 中,我有 2 个 View (ViewController_1 和 secondaryView 的 View ):
当我触摸 Button_1 时,我将 secondaryView 添加为 myTable 的 subview :
- (IBAction)buttonPressed:(id)sender
{
[self.view addSubview:secondView];
}
如何实现带有表的第二个 View 及其方法(DataSource)已在单独的类中实现? 因为如果我有,例如,10 个按钮???那么ViewController_1中就会有很多代码!!!
最佳答案
我建议你使用SecondViewController
而不是 View 。当您点击按钮时,将其导航到该 SecondViewController 。正如您所说,有几个按钮依次导致隐藏、取消隐藏其他几个 View 。那么你就很难管理了。是的,将会有很多很多的编码和标志。
如果您确实想添加 View ,那么您可以将 SecondViewController
保留为 UIViewController
。在那里执行所有表数据源/委托(delegate)方法并
将其添加到 ViewController_1 时
尝试以下代码
- (IBAction)buttonPressed:(id)sender
{
[self.view addSubview:secondViewController.view];
}
关于iphone - UIView 与许多 TableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12005415/