XMPP
使用tableview我试图用特定的用户名转到下一个视图控制器。所以我已经正确地实现了UItablevie的didselectrowatIndexpath
。但是当我点击用户名时,它会给出这样的错误。
应用程序试图在目标上推送一个nil视图控制器。
“<”UINavigationController:0x7fe831dac0d0>。 2015-06-04 14:22:51.063
我已经在appdelegate.m中宣布了故事板。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
ChatViewController *ChatViewController1 = [[ChatViewController alloc]init];
self.storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
return YES;
}
这是我的tableview的Delegate方法。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tblvwbuddy deselectRowAtIndexPath:indexPath animated:YES];
XMPPUserCoreDataStorageObject *user = nil;
user = [[self fetchedResultsController] objectAtIndexPath:indexPath];
ChathistryViewController *chathistory1 = [[ChathistryViewController alloc] init]; // or initWith...
chathistory1 = [appdelegate.storyboard instantiateViewControllerWithIdentifier:@"ChathistryViewController"];//My next view controller's name
chathistory1.chatUserObject = user;
chathistory1.hidesBottomBarWhenPushed = YES;
chathistory1.self.tabBarController.navigationItem.title = user.displayName;
[self.tabBarController.navigationController pushViewController:chathistory1 animated:YES];
}
我错过了什么?或者我错了?
答案 0 :(得分:0)
试试这个:
UITabBarController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"main"];
NSArray *listViewController=vc.viewControllers;
vc.selectedViewController=[listViewController objectAtIndex:1];
[self presentViewController:vc animated:YES completion:nil];
ps .... listViewController objectAtIndex:1< ---表示你想要显示你的viewcontroller的位置
答案 1 :(得分:0)
修改强>
id: 1
select_type: SIMPLE
table: categories
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 4
Extra:
1 row in set (0.00 sec)
结束修改
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
ChatViewController *ChatViewController1 = [[ChatViewController alloc]init];
self.storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//HOW DID YOU DECLARE the rootViewController?
/*
you CANNOT do this:
self.window.rootViewController = ChatViewController1;
*/
//you MUST have declared it like: right? becuase your are using navigationController
UINavigationController *navigationView = self.storyboard instantiateViewControllerWithIdentifier:@"naviController"/*Storyboard ID*/];
self.window.rootViewController = navigationView;
//Manually setting navigationController rootViewController, example your rootViewController is ChatViewController
UIViewController = self.storyboard instantiateViewControllerWithIdentifier:@"ChatViewController"/*Storyboard ID*/];
[navigationView setViewControllers:UIViewController animated:NO];
return YES;
}
在您的情况下,您必须设置自定义类:( ChathistryViewController )
确保您的故事板中存在 chathistory1 = [appdelegate.storyboard instantiateViewControllerWithIdentifier:@"ChathistryViewController"];troller
Storyboard ID
来自您的代码:
ChathistryViewController
我觉得分配它更好:
chathistory1 = [appdelegate.storyboard instantiateViewControllerWithIdentifier:@"ChathistryViewController"];
更好的分配:
//From your code [[ChathistryViewController alloc] init]; will be use less
ChathistryViewController *chathistory1 = [[ChathistryViewController alloc] init];
chathistory1 = [appdelegate.storyboard instantiateViewControllerWithIdentifier:@"ChathistryViewController"];
另一个是你的ChathistryViewController *chathistory1 = [appdelegate.storyboard instantiateViewControllerWithIdentifier:@"ChathistryViewController"];
你在哪里宣布[appdelegate.storyboard instantiateViewControllerWithIdentifier:];
?
您可以通过以下方式访问AppDelegates属性:
appdelegate
答案 2 :(得分:0)
我猜你的故事板没有正确初始化,因为你得到了错误。
不是在委托类中创建storyboard对象,而是按照以下方法检索故事板对象。
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
让我知道它是否有效。