我是一名新生,刚加入一家iphone编程软件公司作为实习生。我是iPhone编程的新手,但不是计算机编程的新手。我不知道如何使用UI按钮切换到下一个视图控制器。
我的编码如下...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (!self.detailViewController) {
self.detailViewController = [[HelloDetailViewController alloc] initWithNibName:@"HelloDetailViewController" bundle:nil];
}
NSDate *object = [_objects objectAtIndex:indexPath.row];
self.detailViewController.detailItem = object;
[self.navigationController pushViewController:self.detailViewController animated:YES];
}
欢迎出国。学习Objective-C编程并不难。不过有很多关于这方面的教程,你可能想熟悉所有的UINavitationController
,UIViewController
以及小部件(UIButton
,UILabel
等)。
因此,要回答您的问题,有两种方法可以做到。
- 在
.h
中创建IBAction
,然后将其连接到 XIB 中的按钮。
-(IBAction) submit;
- 假设您有一个按钮,请拨打
IBOutlet UIButton *myButton
[myButton addTarget:self action:@selector(submit) forControlEvents:UIControlEventTouchUpInside];
您的方法:
-(void) submit{
if (!self.detailViewController) {
self.detailViewController = [[HelloDetailViewController alloc] initWithNibName:@"HelloDetailViewController" bundle:nil];
}
//NSDate *object = [_objects objectAtIndex:indexPath.row];
//self.detailViewController.detailItem = object;
[self.navigationController pushViewController:self.detailViewController animated:YES];
}
只需切换到下一个视图控制器,请编写以下代码
viewcontrollerobject=[[ViewControllerName alloc] initWithNibName:@"ViewControllerXibName" bundle:nil];
[self.view addSubview:viewcontrollerobject.view];
如果您需要导航推送视图控制器动画,请使用代码
[self.navigationController pushViewController:ViewControllerName animated:YES];
这将带您简单地进入下一页。