2011-08-31 57 views
5

我想這樣做,但按鈕不會顯示:如何以編程方式在右上角創建信息按鈕?

// Create a Button to get Help   
UIButton *helpButton = [UIButton buttonWithType:UIButtonTypeInfoDark ] ; 
CGRect buttonRect = helpButton.frame; 

// Calculate the top right corner 
buttonRect.origin.x = self.tableView.frame.size.width - buttonRect.size.width - 8; 
buttonRect.origin.y = self.tableView.frame.size.height - buttonRect.size.height - 8; 
[helpButton setFrame:buttonRect]; 

[helpButton addTarget:self action:@selector(doHelp:) 
forControlEvents:UIControlEventTouchUpInside]; 
[helpButton setEnabled:TRUE]; 
[self.tableView addSubview:helpButton]; 

我究竟做錯了什麼?

UPDATE 修復代碼是在這裏的任何人有興趣:

// Create a Button to get Help   
UIButton *helpButton = [UIButton buttonWithType:UIButtonTypeInfoDark ] ; 
CGRect buttonRect = helpButton.frame; 

// CALCulate the bottom right corner 
buttonRect.origin.x = self.view.frame.size.width - buttonRect.size.width - 8; 
buttonRect.origin.y = buttonRect.size.height - 8; 
[helpButton setFrame:buttonRect]; 

[helpButton addTarget:self action:@selector(doHelp:) forControlEvents:UIControlEventTouchUpInside]; 
[self.view addSubview:helpButton]; 
+3

嘗試將它添加到self.view不self.tableview – TommyG

+0

感謝它做到了! –

+0

肯定沒問題! – TommyG

回答

4

嘗試將它添加到self.view不self.tableview

相關問題