Мне нужен tableView, где я могу выбрать раздел, чтобы добавить к нему элемент. Как? Должен ли я увеличить высоту от 22px до 44px сохранить стиль фона и реализовать обработчик событий в sectionnview? Какой подход вы используете для добавления элемента в раздел?Как выбрать заголовок в UITableView?
0
A
ответ
1
Нет способа сделать это с помощью UITableViewDelegate
.
Создайте пользовательский раздел headerView
, а затем добавьте к нему жест жеста.
LIKE:
UITapGestureRecognizer *singleTapRecogniser = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gestureHandler:)] autorelease];
[singleTapRecogniser setDelegate:self];
singleTapRecogniser.numberOfTouchesRequired = 1;
singleTapRecogniser.numberOfTapsRequired = 1;
[yourHeaderView addGestureRecognizer:singleTapRecogniser];
, а затем:
//This method will be called on Tap of section heade
- (void) handleGesture:(UIGestureRecognizer *)gestureRecognizer{
}
1
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
foundIndex=FALSE;
for (int i=0; i<[indexArray count]; i++)
{
_currentRow=[[indexArray objectAtIndex:i] intValue];
if(_currentRow==indexPath.section)
{
foundIndex=TRUE;
}
}
if (foundIndex==TRUE)
{
return 100;
}
else
{
return 0;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
UIButton *btnCollapse = [UIButton buttonWithType:UIButtonTypeCustom];
[btnCollapse setFrame:CGRectMake(10, 0, 303, 50)];
[btnCollapse setBackgroundColor:[UIColor clearColor]];
[btnCollapse addTarget:self action:@selector(touchedSection:) forControlEvents:UIControlEventTouchUpInside];
btnCollapse.tag = section+600;
[headerView addSubview:btnCollapse];
UILabel *lot_title = [[UILabel alloc]initWithFrame:CGRectMake(13, 2, 270, 20)];
lot_title.numberOfLines=3;
lot_title.backgroundColor=[UIColor clearColor];
lot_title.text=[NSString stringWithFormat:@"%@",[[MyConsignmentData objectAtIndex:section] objectForKey:@"lot_title"]];
lot_title.font = [UIFont boldSystemFontOfSize:14];
lot_title.textColor =[UIColor blackColor];
CGSize maxSize = CGSizeMake(lot_title.bounds.size.width, CGFLOAT_MAX);
CGSize textSize1 = [lot_title.text sizeWithFont:lot_title.font constrainedToSize:maxSize];
lot_title.frame=CGRectMake(13, 2, 270, textSize1.height);
if (textSize1.height+10<40)
{
return 40;
}
else
{
return textSize1.height+10;
}
}
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 50)];
UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(280,tableView.sectionHeaderHeight/2+5 , 22, 22)];
foundIndex=FALSE;
for (int i=0; i<[indexArray count]; i++)
{
_currentRow=[[indexArray objectAtIndex:i] intValue];
if(_currentRow==section)
{
foundIndex=TRUE;
}
}
if (foundIndex==TRUE)
{
img.image = [UIImage imageNamed:@"down-arrow-active.png"];
}
else
{
img.image = [UIImage imageNamed:@"right-arrow-deactive.png"];
}
[headerView addSubview:img];
UIButton *btnCollapse = [UIButton buttonWithType:UIButtonTypeCustom];
[btnCollapse setFrame:CGRectMake(10, 0, 303, 50)];
[btnCollapse setBackgroundColor:[UIColor clearColor]];
[btnCollapse addTarget:self action:@selector(touchedSection:) forControlEvents:UIControlEventTouchUpInside];
btnCollapse.tag = section+600;
[headerView addSubview:btnCollapse];
UIImageView *imgbac;
if (textSize1.height+10<40)
{
imgbac = [[UIImageView alloc]initWithFrame:CGRectMake(8, 0, 303, 40)];
}
else
{
imgbac = [[UIImageView alloc]initWithFrame:CGRectMake(8, 0, 303, textSize1.height+10)];
}
imgbac.image = [UIImage imageNamed:@"mybid-box-bg.png"];
[headerView addSubview:imgbac];
[headerView addSubview:imgbac];
[headerView addSubview:lot_title];
[headerView addSubview:img];
[headerView addSubview:btnCollapse];
headerView.backgroundColor=[UIColor clearColor];
return headerView;
}
- (IBAction)touchedSection:(id)sender
{
NSInteger _index=[sender tag]-600;
foundIndex=FALSE;
NSInteger stored;
for (int i=0; i<[indexArray count]; i++)
{
_currentRow=[[indexArray objectAtIndex:i] intValue];
if(_currentRow==_index)
{
stored=i;
foundIndex=TRUE;
}
}
if (foundIndex==TRUE)
{
[indexArray removeObjectAtIndex:stored];
}
else
{
[indexArray addObject:[NSNumber numberWithUnsignedInteger:_index]];
}
[tableview reloadData];
}
Смежные вопросы
- 1. Как заблокировать заголовок/заголовок в UITableView
- 2. UISearchBar как заголовок UITableView
- 3. Настроить заголовок в UITableView
- 4. UITableView с UITextField как заголовок
- 5. Как разместить заголовок раздела UITableView?
- 6. Как закрепить заголовок секции UITableView?
- 7. Как создать расширяемый заголовок UITableView?
- 8. Как добавить заголовок в раздел в UITableView?
- 9. Заголовок раздела UITableView невидимый
- 10. Заголовок интерактивной секции UITableView
- 11. Исправлен прозрачный заголовок в UITableView
- 12. Удалить заголовок UITableView
- 13. UITableView: заголовок секции привязки
- 14. UITableView скрытый заголовок?
- 15. Вертикальный UITableView Раздел Заголовок
- 16. UITableView фиксированный заголовок
- 17. Заголовок заголовка UITableView Glitch?
- 18. удалить заголовок UITableView разрыв
- 19. Заголовок раздела в uitableview - reusidentifier?
- 20. Как добавить заголовок раздела в UITableView
- 21. Как получить заголовок строки, выбранной в UITableview
- 22. Как удалить пустой заголовок раздела в UITableView
- 23. Как добавить/удалить заголовок раздела в UITableView?
- 24. Прокрутить заголовок UITableView?
- 25. UITableView заголовок не будет придерживаться вершины UITableView
- 26. Заголовок раздела UITableView исчезает
- 27. заголовок UITableView не виден
- 28. UITableView параллакса заголовок
- 29. Устанавливает заголовок из UITableView
- 30. Как программно выбрать ячейку uitableview?