![](/img/trans.png)
[英]Adding a UIViewController to a UINavigationController stack - the correct approach
[英]adding a uinavigationcontroller to a view as part of a stack of uiviews
在我的iphone應用程序中,我首先調用一個控制器,它根據索引堆疊一些視圖控制器。 這是基於用戶的選擇,我需要顯示不同的屏幕(基本上,我有一個歡迎屏幕,標簽欄視圖 - 這是主要的應用程序,登錄和注冊頁面)。 截至目前,一切都運行良好 - 我將它們疊加起來並根據需要移除/切換。 問題是我想在登錄和注冊視圖中添加導航欄。 然而,當我這樣做時,會發生一些奇怪的事情 - 我看到一個導航欄,但在它的頂部,還有一個白色條(半寬或多或少)。 我怎樣才能成功添加這個uinavbar?
這是AppDelegate正在調用的控制器:
- (void)viewDidLoad
{
[super viewDidLoad];
myTabBarVC = [[tabBarController alloc] initWithNibName:@"tabBarController" bundle:nil];
[self.view insertSubview:myTabBarVC.view atIndex:0];
myLoginVC = [[loginViewController alloc] initWithNibName:@"loginViewController" bundle:nil];
[self.view insertSubview:myLoginVC.view atIndex:1];
mySignUp = [[SignUpView alloc] initWithNibName:@"SignUpView" bundle:nil];
[self.view insertSubview:mySignUp.view atIndex:2];
myWelcomeView = [[WelcomeView alloc] initWithNibName:@"WelcomeView" bundle:nil];
[self.view insertSubview:myWelcomeView.view atIndex:3];
}
當我在同一方法中將其添加到其中一個視圖控制器時,它不起作用,如上所述。
myLoginVC = [[loginViewController alloc] initWithNibName:@"loginViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myLoginVC];
[self.view insertSubview:navController.view atIndex:1];
我怎樣才能使它工作? 請幫忙。 謝謝!
添加更多關於鍵盤在默認情況下打開的視圖的信息:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if( cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
cell.textLabel.text = [[NSArray arrayWithObjects:@"",@"",nil]
objectAtIndex:indexPath.row];
if (indexPath.row == 0) {
textField1 = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 280, 21)];
textField1.delegate = self;
textField1.placeholder = @"example@EMAIL.com";
textField1.text = [inputTexts objectAtIndex:indexPath.row/2];
textField1.tag = indexPath.row/2;
cell.accessoryView = textField1;
textField1.returnKeyType = UIReturnKeyNext;
textField1.clearButtonMode = UITextFieldViewModeWhileEditing ;
[textField1 becomeFirstResponder];
textField1.tag = 1;
}
else
{
textField2 = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 280, 21)];
textField2.delegate = self;
textField2.placeholder = @"password";
textField2.text = [inputTexts objectAtIndex:indexPath.row/2];
textField2.tag = indexPath.row/2;
textField2.returnKeyType = UIReturnKeyDone;
textField2.clearButtonMode = UITextFieldViewModeWhileEditing;
cell.accessoryView = textField2;
[textField1 becomeFirstResponder];
textField1.tag = 2;
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
我認為您不應該將navController.view添加為視圖控制器的子視圖。 我懷疑這是麻煩的根源。 而是使用UINavigationBar對象。
關於你的第二個問題,如果這是一個問題,而不是一個評論,關於鍵盤默認情況下,這是因為你將textField1設置為第一響應者。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.