Я пытаюсь понять, как добавить метку с UISwitch или другим контроллером в нижний колонтитул (или заголовок) в разделенном tableView. Любая помощь будет принята с благодарностью. Заранее спасибо!Как добавить UIButton или UISwitch в tableView: viewForFooterInSection
6
A
ответ
8
Хорошо, после поиска и работы на ней я сделал следующее:
// Need to refactor so that the label is Public Sharing and Priviate Sharing and the actions work for each switch
- (UIView *) tableView: (UITableView *) tableView
viewForFooterInSection: (NSInteger) section
{
if (section == 0 || section == 1) {
CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
UIView* footerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, screenRect.size.width, 44.0)] autorelease];
footerView.autoresizesSubviews = YES;
footerView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
footerView.userInteractionEnabled = YES;
footerView.hidden = NO;
footerView.multipleTouchEnabled = NO;
footerView.opaque = NO;
footerView.contentMode = UIViewContentModeScaleToFill;
// Add the label
UILabel* footerLabel = [[UILabel alloc] initWithFrame:CGRectMake(150.0, -5.0, 120.0, 45.0)];
footerLabel.backgroundColor = [UIColor clearColor];
footerLabel.opaque = NO;
footerLabel.text = @"Sharing";
footerLabel.textColor = [UIColor tableHeaderAndFooterColor];
footerLabel.highlightedTextColor = [UIColor tableHeaderAndFooterColor];
footerLabel.font = [UIFont boldSystemFontOfSize:17];
footerLabel.shadowColor = [UIColor whiteColor];
footerLabel.shadowOffset = CGSizeMake(0.0, 1.0);
[footerView addSubview: footerLabel];
[footerLabel release];
// Add the switch
UISwitch* footerSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(215.0, 5, 80.0, 45.0)];
[footerView addSubview: footerSwitch];
// Return the footerView
return footerView;
}
else return nil;
}
// Need to call to pad the footer height otherwise the footer collapses
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
switch (section) {
case 0:
case 1:
return 40.0;
default:
return 0.0;
}
}
Я надеюсь, что это правильно, и если это поможет кому-либо еще, пожалуйста, оцените это. Ура!
0
я думаю, что вам нужно autorelease в uiview-
0
я использовал код, подобный тому, что ... но я добавил вызов NSLog() сразу после addSubview.
Когда я прокручивать мой Tableview ... Я получаю 100s из сообщения, как:
> Adding another subview
> Adding another subview
> Adding another subview
> Adding another subview
> Adding another subview
> Adding another subview
Это нормально? Я только хотел ОДИН кнопка, в ОДИН вид, в самом низу моего TableView.
Смежные вопросы
- 1. Добавить UISwitch только одну ячейку в TableView
- 2. UISwitch в TableView в коммутаторе
- 3. iPhone UIButton с функциональностью UISwitch
- 4. Как связать UISwitch с UIButton в RxSwift?
- 5. viewForFooterInSection сделал догружать
- 6. кнопку Добавить в Tableview сноске
- 7. UISwitch и UIButton в UITableViewCell, как их идентифицировать
- 8. UISwitch Сбрасывает при прокрутке TableView
- 9. Обновить состояние UISwitch при нажатии в TableView
- 10. Как добавить UIButton в UIButton
- 11. Добавить поведение в UISwitch
- 12. Сохранение и загрузка состояния UISwitch в TableView
- 13. UITableView viewForFooterInSection показывает только после прокрутки
- 14. UITableView разделитель ушел при использовании viewForFooterInSection
- 15. Как добавить UISWitch в несколько строк в UITable в iOS?
- 16. viewForFooterInSection необходимо установить нижний колонтитул фиксированное абсолютное положение
- 17. Могу ли я добавить UISwitch, UIButton и метку в заголовок таблицы Customerview (не заголовок раздела)
- 18. добавление UIButton к Tableview headerView
- 19. UISwitch меняет ячейку при прокрутке tableview
- 20. Как добавить UIButton в UITableViewCell динамически?
- 21. Как я мог бы добавить UISwitch в UITableView
- 22. UISwitch, если/else для фильтрации TableView
- 23. Как добавить UISwitch в сгруппированный вид таблицы?
- 24. Как добавить пользовательский UIButton в ячейку таблицы?
- 25. UIButton не работает в Tableview клетки
- 26. Как добавить 3dtouchforce в UIButton?
- 27. Как добавить недвижимость в UIButton?
- 28. UISwitch в функциональности UINavigationBar
- 29. TableView для изменения с помощью UIButton на другом диспетчере представлений
- 30. Позиционирование UISwitch в UITableViewCell вправо