10

您好,我正在使用工具栏上的一个标签栏按钮,此按钮将显示带有表格视图的下一个视图,这是我的代码

[self presentModalViewController:self.navigationController
                            animated:YES];

我的问题是,当我单击此选项卡栏按钮时,它将显示带有 tableview 但不显示导航栏的下一个视图。因此,我无法在 tableView 中执行删除操作。

如何解决问题?

4

7 回答 7

37

如果你没有找到UINavigationBaron next class 的意思,它没有导航控制器,所以在推送它之前添加一个UINavigationController到你的下一个视图。

试试这样:

NextViewController *nextViewController=[[NextViewController alloc]initWithNibName:@"NextViewController" bundle:nil];
UINavigationController *navBar=[[UINavigationController alloc]initWithRootViewController:nextViewController];
[self.navigationController presentModalViewController:navBar animated:YES];
[navBar release];
[nextViewController release];

有关编辑选项,请参阅此stackoverflow 问题

您可以轻松地向导航栏添加一个按钮

self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(editTable)] autorelease];

-(void)editTable{
[tableView setEditing: YES animated: YES];
}

祝一切顺利。

于 2011-05-19T10:46:57.843 回答
3

此代码在 A 类 VC 中的按钮单击事件上调用:

ClassBVC* bVc = [[ClassBVC alloc] initWithNibName:@"ClassBVC" bundle:nil];
     UINavigationController* tempNavCon = [[UINavigationController alloc]    initWithRootViewController:bVc];
    [self presentModalViewController:tempNavCon animated:YES];
    [tempNavCon release];
    [bVc release];
    bVc = nil

;

并且在视图中的 BVC 类中确实加载了您制作的 UIbarbutton 项目,例如:

UIBarButtonItem* barButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(backButtonClicked:)];
    [barButton setTitle:@"Back"];
    [self.navigationItem setLeftBarButtonItem:barButton];
    [barButton release];

在 buttonClickedMethod 中,只需将模型控制器解散为:

-(void)backButtonClicked:(id)sender
{
    [self dismissModalViewControllerAnimated:YES];
}
于 2012-01-05T14:24:50.723 回答
1

那是因为您正在使用 Modal 来带来新的视图控制器。

模态添加/呈现的视图控制器不会被添加到导航控制器堆栈中

于 2013-06-25T19:37:09.073 回答
0

如果您使用的是这样的导航控制器

[self.navigationController pushViewController:nextController animated:YES];
于 2011-05-19T09:51:05.110 回答
0

使用栏按钮将导航栏作为子视图添加到新视图。

试试这个

-(IBAction) editClick:(id)sender
{
    [tableView setEditing:![tableView isEditing]  animated:YES];
}
于 2011-05-19T10:13:42.150 回答
0

斯威夫特 5

 import UIKit

class ListVC: UIViewController {


    // MARK: - Init
    override func viewDidLoad() {
           super.viewDidLoad()

        //Background of the first screen
        view.backgroundColor = .yellow

        //Calling the instance of the navigation controller
        let nav = self.navigationController?.navigationBar

        //Defining the black theme on the navigation controller
        nav?.barStyle = UIBarStyle.black

        //Defining the white characters to make contrast with the black theme on the navigation controller
        nav?.tintColor = UIColor.white

        //Defining the custom color of the title font from navigation controller
        nav?.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.orange]

        //Defining the title of the navigation controller
        nav?.topItem?.title = "List"

        navigationItem.rightBarButtonItem = UIBarButtonItem.init(image: #imageLiteral(resourceName: "AddBtn"), style: .plain, target: self, action: #selector(hello))



//        print(Realm.Configuration.defaultConfiguration.fileURL)

           let realm = try! Realm()

           print(Realm.Configuration.defaultConfiguration.fileURL)

       }


    // MARK: - Selector

    /// A selector function that is called when the 'add' button is pressed on the navigation controller
    @objc func hello() {

        //Instance of the second screen
        let addVC = AddVC()

        //Add the navigationController to the new viewController
        let navController = UINavigationController(rootViewController: addVC)

        //Presenting the second screen modally
        navigationController?.present(navController, animated: true, completion: nil)
    }


}
//Other class
import UIKit

class AddVC: UIViewController {


    override func viewDidLoad() {
        super.viewDidLoad()

        //Background of the view
        view.backgroundColor = .white

        //Calling the instance of the navigation controller
        let nav = self.navigationController?.navigationBar

        //Initialize the title for the ViewController
        nav?.topItem?.title = "Andrey"

        // Initialize the right bar button item
        navigationItem.rightBarButtonItem = setUpSaveButton()
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.setNavigationBarHidden(false, animated: true)
    }

    /// Function that returns the "Save" bar button item
    private func setUpSaveButton() -> UIBarButtonItem {
        let button = UIBarButtonItem(title: "Save", style: .plain, target: self, action: #selector(saveAction))
        button.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.systemBlue],
                                      for: .normal)

        return button
    }

    @objc func saveAction() {
        print("Saving..")
    }
}

于 2020-02-07T23:40:02.510 回答
0

Swift 5.1 在全屏模式下呈现带有导航栏和工具栏的 ViewController。如果您不将标记的行放在注释上,则工具栏永远不会显示出来。

let sb = UIStoryboard(name: "retail_mainScreen", bundle: nil)
        guard let mainVC = sb.instantiateViewController(withIdentifier: "mainScreen") as? retail_mainGest else { return }
        let navController = UINavigationController(rootViewController: mainVC)
        navController.isToolbarHidden = false //<--- remember this or toolbar will not appear
        navController.modalPresentationStyle = .fullScreen

         sender.vista.present(navController, animated: true, completion: nil)
于 2020-05-29T13:55:33.297 回答