У меня есть UIViewController
с UITableView
. В tableview есть настроенные ячейки с текстовыми полями внутри него. Делегаты текстового поля настроены на этот класс.
При редактировании текстового поля (textFieldDidBeginEditing
) у меня есть drop down (UIView
с табличным представлением в нем). Выпадающий список создается программно.
Проблема, с которой я столкнулся, заключается в том, что didSelectRowAtIndexPath
раскрывающегося списка таблиц не вызывается. Я правильно поставил делегат, источник данных для класса. Я также удалил все остальные жесты. Я убедился, что tableview не находится в режиме редактирования.
При щелчках ячеек в раскрывающемся списке единственное, что работает, это методы делегата в текстовом поле background background.
//UITableView class(with textfield from where dropdown is loaded.)
- (void)textFieldDidBeginEditing:(UITextField *)textField{
if(textField.tag == 3){
if(dropDown == nil) {
CGFloat f = 200;
dropDown = [[SFTextFieldDropDown alloc] showDropDownWithSender:textField withHeight:f andElements:self.list];
dropDown.delegate = self;
}
}
}
// Custom Drop down class.
- (id)showDropDownWithSender:(UITextField *)senderTextField withHeight:(CGFloat)height andElements:(NSArray *)array{
table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, btn.size.width, 0)];
table.delegate = self;
table.dataSource = self;
table.layer.cornerRadius = 5;
table.backgroundColor = [UIColor colorWithRed:0.239 green:0.239 blue:0.239 alpha:1];
table.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
table.separatorColor = [UIColor grayColor];
[table setAllowsSelection:YES];
table.frame = CGRectMake(0, 0, btn.size.width, *height);
[table setEditing:NO];
[self addSubview:table];
}
return self;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 40;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.list count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.textLabel.font = [UIFont systemFontOfSize:15];
cell.textLabel.textAlignment = NSTextAlignmentLeft;
cell.selectionStyle = UITableViewCellSelectionStyleDefault;
}
if([list count] > 0)
cell.textLabel.text = [list objectAtIndex:indexPath.row];
return cell;
}