我有一个头文件是
@interface DemoFirstViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@end
在这个头文件的源文件中我已经声明了这个方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
AnotherViewController *anotherViewController=[[AnotherViewController alloc] initWithNibName:@"AnotherViewController" bundle:nil];
[self.navigationController pushViewController:anotherViewController animated:YES];
NSLog(@"didSelectRowAtIndexPath: row=%d", indexPath.row);
}
和另一个ViewController 文件是
@interface AnotherViewController : UIViewController
{
IBOutlet UILabel *message;
}
@property (nonatomic , retain) UILabel *message;
@end
我正在使用 Xib 文件完成这一切。不是故事板。
这是tabbased Application
. 并且已经在 Appdelegate 中声明了两个视图控制器
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewController1 = [[DemoFirstViewController alloc] initWithNibName:@"DemoFirstViewController" bundle:nil];
UIViewController *viewController2 = [[DemoSecondViewController alloc] initWithNibName:@"DemoSecondViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[viewController1, viewController2];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
bt 在点击表格单元格时,anotherViewcontroller 没有出现。请尽快回复。