2012-08-11 136 views
0

我新的IOS ..添加导航栏的UITableView编程

我要的是有超过UITableView导航栏,这里面我-(void) loadView

我的代码是这样创造.. 。

(void)loadView { 
    [super loadView];  

    CGRect frame = CGRectMake(0, 0, 320, 480); //define size and position of view 
    tableView1= [[UITableView alloc]initWithFrame:frame style:UITableViewStylePlain ]; 
    tableView1.editing=YES; 
    tableView1.dataSource=self; 
    tableView1.delegate=self; 

    //navigationItem= [[UIBarButtonItem alloc]initWithTitle:@"Names" style:UIBarButtonItemStyleBordered target:self action:@selector(first:) ]; 
    //self.navigationItem.leftBarButtonItem=btnBarItem; 

    [self.view addSubview:tableView1]; 
} 

我想对我分配的,这样我可以插入一个添加按钮的tableview导航栏..

任何帮助将是一个高度ppreciated ...

+0

发生了什么呢上面显示它解决你的问题:) ??????????? – 2012-08-11 12:46:03

+0

可能重复[以编程方式向UITableViewController添加NavigationBar?](http://stackoverflow.com/questions/2700990/adding-a-navigationbar-to-uitableviewcontroller-programmatically) – 2015-11-12 15:49:44

回答

0

因为你是iOS开发新手,我不知道你是否熟悉iOS中的导航模式。

看看Navigation Controllers的文档,然后你应该使用UINavigationViewControllerUITableViewController。在UINavigationViewController上推UITableViewController,并且您的导航栏位于顶部。

+0

谢谢anka:)...我知道这个方法但我想知道我们是否可以直接插入导航栏到tableview中而不使用UInavigationController? – naveen 2012-08-11 10:15:30

+0

不,这是不可能的,但你可以把导航栏在视图:) – 2012-08-11 11:32:56

0

只是把这个代码

必须将其删除,因为它仅仅是导致错误:)

编辑1

对不起小姐理解。这是可行的解决方案。

你需要采取的UINavigationController中的appDelegate主容器和分配你的第一个的viewController给它的,因为我以前在代码中像

UINavigationController *ePicker = [[UINavigationController alloc] initWithRootViewController:firstViewController]; 

做根的viewController,然后你会得到导航栏上的实现代码如下

编码快乐:)

编辑2

如果你只是想要一个导航栏不是navigationViewController则只是把这个线

UINavigationBar *navBar = [[UINavigationBar alloc]init]; 
    [self.view addSubview:navBar]; 

在viewDidLoad方法和导航栏将tabelView

编码快乐:)

+0

获取警告分配(UINavigationController *导航)不兼容Objective-C类型的结构UITableView *',预期'结构UIViewController *'时传递参数1'initWithRootViewController :'from distinct Objective-C type ..... and([self.view addSubview:nav]; )incompatible Objective-C types'struct UINavigationController *',expected'struct UIView *'when passed argument 1 of'addSubview :'从不同的Objective-C类型 – naveen 2012-08-11 11:13:43

+0

对不起,我想念下站在所有检查我的编辑1部分:) – 2012-08-11 11:17:02

+0

对不起,我不能看到你的编辑部分1 .. – naveen 2012-08-11 11:26:04