Objective c pushViewController不使用选项卡栏控制器
我正在尝试使用以下代码推入一个新的视图控制器:Objective c pushViewController不使用选项卡栏控制器,objective-c,xcode,uinavigationcontroller,uitabbarcontroller,pushviewcontroller,Objective C,Xcode,Uinavigationcontroller,Uitabbarcontroller,Pushviewcontroller,我正在尝试使用以下代码推入一个新的视图控制器: [self.navigationController pushViewController:webViewController animated:YES]; 但它不起作用。当您在“我的表格”视图中选择单元格时,会发生此代码。我有一个表视图,我认为它阻止了这种情况的发生。我尝试过用模式来展示它,但那会去掉导航栏,我无法回头。有一个非常类似的问题,但答案对我不起作用 更新 - (void)loadView { // Create an ins
[self.navigationController pushViewController:webViewController animated:YES];
但它不起作用。当您在“我的表格”视图中选择单元格时,会发生此代码。我有一个表视图,我认为它阻止了这种情况的发生。我尝试过用模式来展示它,但那会去掉导航栏,我无法回头。有一个非常类似的问题,但答案对我不起作用
更新
- (void)loadView {
// Create an instance of UIWebView as large as the screen
CGRect screenFrame = [[UIScreen mainScreen] applicationFrame];
UIWebView *wv = [[UIWebView alloc] initWithFrame:screenFrame];
// Tell web view to scale web content to fit within bounds of webview
[wv setScalesPageToFit:YES];
[self setView:wv];
[wv release];
}
将web视图作为WebViewController的视图
没有如上所示的笔尖
使用NSLog调用didSelect cell方法来查找
所有内容都已初始化和分配,且不为零
更新:
我的did选择单元格方法:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Push the web view controller onto the navigaton stack - this implicity
// creates the web view controller's view the first time through
NSLog(@"TOUCHED!");
webViewController = [[WebViewController alloc] init];
if (webViewController == nil) {
NSLog(@"webViewController in nil state");
}
[self.navigationController pushViewController:webViewController animated:YES];
// Grab the selected item
RSSItem *entry = [[channel items] objectAtIndex:[indexPath row]];
// Construct a URL with the link string of the item
NSURL *url = [NSURL URLWithString:[entry link]];
// Construct a request object with that URL
NSURLRequest *req = [NSURLRequest requestWithURL:url];
// Load the request into the web view
[[webViewController webView] loadRequest:req];
// Set the title of the web view controller's navigation item
[[webViewController navigationItem] setTitle:[entry title]];
}
在插入选项卡栏控制器之前,所有这些都起到了作用
更新
- (void)loadView {
// Create an instance of UIWebView as large as the screen
CGRect screenFrame = [[UIScreen mainScreen] applicationFrame];
UIWebView *wv = [[UIWebView alloc] initWithFrame:screenFrame];
// Tell web view to scale web content to fit within bounds of webview
[wv setScalesPageToFit:YES];
[self setView:wv];
[wv release];
}
我在其中创建控制器(应用程序内委托):
所以我真的不知道这里发生了什么。还有,如果你能帮我问另一个问题!转到我的个人资料,查看有关如何在uitableviewcell中停止截断/为文本标签添加额外行的问题。是否按如下方式执行此操作
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(reqList==Nil)
{
reqList = [[RequestList alloc]initWithNibName:@"RequestList" bundle:nil];
}
[self.navigationController pushViewController:reqList animated:YES];
}
要使推送成功,您必须检查几点 首先,要推送的视图控制器可能被设计并存储在NIB文件中。检查如何在代码中创建它,特别是NIB文件名(假设您使用
-(id)initWithNibName:(NSString*)nibName bundle:(NSBundle*)nibBundle
)。它必须是没有NIB/XIB扩展名的真实NIB文件名
第二,选择事件是否已触发,消息是否真的发送到表视图委托?您可以设置一些日志来确保这一点。表视图不会阻止视图控制器被推送到导航堆栈上
问题并不是关于如何/在何处创建该控制器,因此最后,如果这些都不起作用,请在按下之前对控制器进行alloc/init测试。您可能对正在发生的事情有了更好的了解。我在您的应用程序代理中没有看到初始的UINavigationViewController。要使用self.navigationController pushViewController,视图控制器需要位于self.navigationController.ViewController之一中。你可以修改你的代码,然后尝试下面的方法,看看它是否适合你
// Create two view controllers
UIViewController *vc1 = [[ListViewController alloc] initWithStyle:UITableViewStyleGrouped];
UIViewController *vc2 = [[YoutubeViewController alloc] init];
// Create the UINavigationController and put the list view controller as the root view controller
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:vc1];
// Make an array containing the two view controllers and the UINavigationController which has the ListViewController is the first one.
NSArray *viewControllers = [NSArray arrayWithObjects:navController, vc2, nil];
// The viewControllers array retains vc1 and vc2, we can release
// our ownership of them in this method
[vc1 release];
[vc2 release];
[navController release];
// Attach them to the tab bar controller
[tabBarController setViewControllers:viewControllers];
如果视图控制器位于“更多”按钮下,则情况会发生一些变化 以下是我了解使用哪种导航控制器的方法:
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
UITabBarController *tabBar = (UITabBarController*) self.window.rootViewController;
UINavigationController* navigationController = (UINavigationController*)self.tabBarController.selectedViewController;
UIViewController* top = nil;
if ([navigationController respondsToSelector:@selector(topViewController)]) {
top = navigationController.topViewController;
}
// the actual current navigation controller depends on whether we are on a view under the More tab
UINavigationController *curNavController;
if (top == nil) { // this implies a view under the More tab
curNavController = tabBar.moreNavigationController;
} else {
curNavController = navigationController;
}
[[LocalNotificationMgr Get] ReceivedNotification:notif navController:curNavController];
}
基本上,如果用户位于“更多”选项卡下的视图上,则要用于将UIViewController推送到其上的实际当前UINavigationController是UITabBarController的moreNavigationController属性。
如果在选项卡栏上实际可见的视图上,请使用UITabBarController的selectedViewController属性。
注意:如果您在“更多屏幕”上,您可以使用任意一个属性。但是我在另一个地方初始化了它,因此它不为零/不为零,并且仍然不起作用。您查看的是什么设置?是否将UINavigationController作为根视图控制器,并且在视图中有一个选项卡栏控制器,或者选项卡栏控制器是根视图控制器,其中一个选项卡项是UINavigationController?我将选项卡栏控制器作为根视图控制器我设置了两个视图控制器的数组(一个表视图和一个视图控制器)作为选项卡栏控制器的视图控制器。在两个视图控制器的init和initWithStyle方法中,我制作了一个uibaritem。不,它不是nib,它是一个web视图,我在loadView方法中这样做:-(void)loadView{//创建一个与屏幕CGRect screen FRAME=[[UIScreen mainScreen]applicationFrame]一样大的UIWebView实例;UIWebView*wv=[[UIWebView alloc]initWithFrame:screenFrame];//告诉web视图缩放web内容以适应webview的范围[wv setScalesPageToFit:YES];[self setView:wv];[wv release];}然后我将请求加载到其他地方。使用nslog调用didSelect cell方法,但它不必是nib,在我放入选项卡栏控制器之前,它在没有nib的情况下工作注意“top”可以很容易地替换为一个普通的布尔值,指示是否响应选择器。不管怎样,您的解决方案对我很有效。非常感谢!