2013-02-27 47 views
0

我可以在界面構建器中的現有視圖中添加一個tableview。我可以使用其他控件將視圖添加到視圖嗎?

我的接口生成器看起來像下面

enter image description here

但是,當我在模擬器中運行的代碼,你可以看到,因爲它覆蓋的按鈕表中沒有在同一個地方顯示爲界面生成器在底部 ???

enter image description here

更新中...我有點取得進展,但在底部的按鈕被隱藏?

enter image description here

固定...與您所附加的建議如下面的代碼:)

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { 

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 40)]; 

view.backgroundColor = [UIColor whiteColor]; 

UIButton *buttonA = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
buttonA.frame = CGRectMake(101,5,118,29); 
[buttonA setTitle:@"Save & Exit" forState:UIControlStateNormal]; 
buttonA.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; 

[view addSubview:buttonA]; 

UIButton *buttonB = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
buttonB.frame = CGRectMake(254,5,56,29); 
[buttonB setTitle:@"Next" forState:UIControlStateNormal]; 
buttonB.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; 

[view addSubview:buttonB]; 

return view; 

}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { 
return 40; 

}

+0

可能是因爲自動對齊。 – KingofBliss 2013-02-27 09:28:17

+0

不確定,但檢查自動調整您的tableview。 – 2013-02-27 09:36:09

+0

是的你可以,並猜測你已經做了什麼:)。休息只是解除底部並在你的tableView中添加streaching。 – rptwsthi 2013-02-27 09:46:12

回答

0
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section 

在數據源方法返回頁腳視圖(其包含 「保存&編輯」 了UIView和 「下一個」 UIButtons)。

+0

我不確定這種方法需要做什麼?我已經用最新的屏幕截圖更新了我的問題 - 正如您所見 - 由於某種原因,按鈕被隱藏了? – rs2000 2013-02-27 17:45:55

+0

創建一個UIView並將按鈕添加到該視圖對象,並返回我提到的方法。試試吧......看看。 – damithH 2013-02-28 04:09:18

+0

這個方法是一個UITableViewDataSource方法,並且在爲相關部分創建節頁腳時觸發。 – damithH 2013-03-01 11:05:54

0

確保tablevi的代表和數據源立即向文件所有者發送。你也必須實現這兩種方法。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; 

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier: 
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls) 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; 

Check this link for example!

0

應用自動調整大小到的.xib文件如下那些子視圖....

enter image description here

您可以通過編程使用以下功能更改..

UIViewAutoresizing 
Specifies how a view is automatically resized. 

enum { 
    UIViewAutoresizingNone     = 0, 
    UIViewAutoresizingFlexibleLeftMargin = 1 << 0, 
    UIViewAutoresizingFlexibleWidth  = 1 << 1, 
    UIViewAutoresizingFlexibleRightMargin = 1 << 2, 
    UIViewAutoresizingFlexibleTopMargin = 1 << 3, 
    UIViewAutoresizingFlexibleHeight  = 1 << 4, 
    UIViewAutoresizingFlexibleBottomMargin = 1 << 5 
}; 

的示例是:

[yourViews.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoResizingFlexibleWidth]; 
相關問題