Если вы посмотрите на библиотеку JavaScript Algolia Places , это те данные, с которыми они имеют дело, прежде чем они передаются в автозаполнение.
Вы должны найти все, что вам нужно в этом коде, а точнее для полного отображаемого имени найденного места, это построено из этого:
const out = `${name}${type !== 'country' && country !== undefined ? ',' : ''}
${city ? `${city},` : ''}
${administrative ? `${administrative},` : ''}
${country ? country : ''}`
.replace(/\s*\n\s*/g, ' ')
.trim();
return out;
(найдено в formatInputValue.js file
] `)
var last_selected:IndexPath!
определяют last_selected:IndexPath в классе
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath) as! Cell
cell.contentView.backgroundColor = UIColor.lightGray
cell.txt.textColor = UIColor.red
if(last_selected != nil){
//deselect
let deselect_cell = tableView.cellForRow(at: last_selected) as! Cell
deselect_cell.contentView.backgroundColor = UIColor.white
deselect_cell.txt.textColor = UIColor.black
}
last_selected = indexPath
}
Если вы говорите о выбранных ячейках, свойство имеет вид -selectedBackgroundView
. Это будет показано, когда пользователь выберет вашу ячейку.
Мне повезло со следующими:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
bool isSelected = // enter your own code here
if (isSelected)
{
[cell setBackgroundColor:[UIColor colorWithRed:1 green:1 blue:0.75 alpha:1]];
[cell setAccessibilityTraits:UIAccessibilityTraitSelected];
}
else
{
[cell setBackgroundColor:[UIColor clearColor]];
[cell setAccessibilityTraits:0];
}
}
Изменение свойства selectedBackgroundView - правильный и самый простой способ. Я использую следующий код для изменения цвета выделения:
// set selection color
UIView *myBackView = [[UIView alloc] initWithFrame:cell.frame];
myBackView.backgroundColor = [UIColor colorWithRed:1 green:1 blue:0.75 alpha:1];
cell.selectedBackgroundView = myBackView;
[myBackView release];