Как создать информационную кнопку программно в правом верхнем углу? - PullRequest
5 голосов
/ 31 августа 2011

Я пытаюсь это сделать, но кнопка не отображается:

// 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];

1 Ответ

4 голосов
/ 31 августа 2011

попробуйте добавить его в self.view, а не в self.tableview

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...