2012-08-11 108 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