我试图在点击下一个按钮后显示UITableView,我无法让它工作......
我不知道为什么TimesViewController.m无法正常工作,如何链接它......
-(IBAction)nextView:(UIBarButtonItem *) sender{
[self pushViewController:TimesTableViewController.m animated:YES];
}
答案 0 :(得分:3)
您需要通读View Controller programming guide。从本质上讲,它更多地取决于您的应用程序设计。最常见的方法是:
使用任何一种方法,您都需要为表视图创建一个单独的视图控制器,它将管理表视图并充当它的委托/数据源。
在你的按钮动作处理程序中,你需要这样做:
-(IBAction)nextView:(UIBarButtonItem *) sender{
MyTableViewController *tableController = [[MyTableViewController alloc] init];
// For #1 above
[self presentViewController:tableController animated:YES completion:^{
// Any code that you want to execute once modal presentation is done
}];
// For #2 above
[self.navigationController pushViewController:tableController animated:YES];
}
修改强>
在MyTableViewController上创建一个initialize方法,并在调用它时传递值。
- (id)initWithData1:(NSString *)iData1 data2:(NSString *)iData2 {
if ((self = [super init])) {
self.data1 = iData1;
self.data2 = iData2;
}
return self;
}
MyTableViewController *tableController = [[MyTableViewController alloc] initWithData1:@"Some String" data2:@"Another string"];
PS:您还可以在MyTableViewController的头文件中公开字符串属性,并从被调用者类中设置它
答案 1 :(得分:0)
或者如果您想以编程方式执行此操作,请在viewDidLoad中创建按钮后
[firstsessionButton addTarget:self action:@selector(showtable:) forControlEvents:UIControlEventTouchUpInside];
-(void)showtable:(UIButton *)sender{
TableViewController *tableViewController=[[TableViewController alloc]init];
[self.navigationController pushViewController:tableViewController animated:YES];
}