我做了这个:
UITextField *searchBarTextField = [self.searchField valueForKey: @"_searchField"];
UITextRange *selRange = searchBarTextField.selectedTextRange;
UITextPosition *selStartPos = selRange.start;
NSInteger idx = [searchBarTextField offsetFromPosition:searchBarTextField.beginningOfDocument toPosition:selStartPos];
idx = idx + 150;
[Util selectTextForInput:searchBarTextField atRange:NSMakeRange(idx, 50)];Util.m
+ (void)selectTextForInput:(UITextField *)input atRange:(NSRange)range {
UITextPosition *start = [input positionFromPosition:[input beginningOfDocument]
offset:range.location];
UITextPosition *end = [input positionFromPosition:start
offset:range.length];
[input setSelectedTextRange:[input textRangeFromPosition:start toPosition:end]];
}但它不会重新定位我的光标。少了什么?
发布于 2014-08-16 22:50:29
在tableView`s的委托方法中创建标签,将标签添加到UISearch栏中。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//get the content of selected cell
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
// now you can get the any content of the selected cell , for example
//Create your label
UILabel *label = [UILabel alloc] init];
label.text = selectedCell.label.text;
/...customize your label as you wish .../
//lastly add the label to the UISearch
[yourSearchBar addSubView: label];
}https://stackoverflow.com/questions/25343912
复制相似问题