大家好我正在使用UITableView和Swift中的UISearchBar开发新的应用程序,它已经正常工作了.但由于最终项目必须有一个完整的自定义搜索栏,因此我不得不移动到UITextField作为输入Outlet,因为它具有自定义功能.
问题是我无法弄清楚如何编码,以便UITextField的行为类似于UISearchBar.不知道如何过滤UITextField输入并使字符串可用于UISearchBarDelegate方法.
所以任何人都可以帮我解决这个问题?
编辑:我跟随丹尼尔的帮助,并提出了这个代码,但它返回"零",没有工作.
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate {
@IBOutlet weak var txtSearchBar: UITextField!
var searchTxt = ""
let prods = ["água", "terra", "ar", "fogo"]
var searchResults:[String] = []
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
txtSearchBar.delegate = self
}
func textFieldDidEndEditing(textField: UITextField) {
searchTxt = textField.text
println(searchTxt)
searchResults = prods.filter({(produtos:String) -> Bool in
let nameMatch = produtos.rangeOfString(self.searchTxt, options: NSStringCompareOptions.CaseInsensitiveSearch)
println(nameMatch)
return nameMatch != nil})
}
Run Code Online (Sandbox Code Playgroud)
我的输入是字母"ar",但它返回"nil",因为它不应该是因为其中一个数组的对象是"ar".
我有这个股票市场计算器,我正在研究,我在StackOverFlow搜索Apple文档,互联网,但没有成功找到答案..
我有一个UITextfield用户将输入货币值.我想要实现的是当用户键入时或者至少在他完成输入值之后,文本字段还将显示与他所在的语言环境相对应的货币符号.
它就像一个占位符,但不是我们在xcode中所拥有的那个,因为xcode是在我们键入之前存在的,而我想要的那个应该在打字时和之后存在.我可以使用带有货币的背景图像,但之后我无法本地化应用程序.
所以如果有人能提供帮助,我将不胜感激.
提前致谢.
嘿家伙我从NSData得到这个输出:<00000100 84000c00 071490fe 4dfbd7e9>
那么我怎样才能在Swift中对其进行字节反转并输出:<00000001 0084000c 1407fe90 fb4de9d7>?
我有一个核心数据应用程序,其模型设置如下图所示:
关系设置如下:
类别<-->>子类别<-->>项目
现在,是否可以在一次提取中从具有名为“categoryName”的相同属性的 Subcategory 和 Item 实体获取对象?我认为可以通过使用关系来完成,但我使用的代码不起作用,即:
let fetchNote = NSFetchRequest(entityName: "Category")
fetchNote.predicate = NSPredicate(format: "ANY subcategory.name == %@ AND item.name == %@", "Badaue", "Badaue")
let notes = try! appDel.managedObjectContext.executeFetchRequest(fetchNote) as? [Category]
print(notes)
Run Code Online (Sandbox Code Playgroud) 我被困在试图从网站上获取一系列时间.我得到的阵列恰好是这个:
NSArray *rawData = @[@"8:06", @"8:07", @"8:08", @"8:09", @"8:10", @"8:11", @"8:12", @"8:13",@"8:14", @"8:15", @"8:16", @"8:17", @"8:18", @"8:19", @"8:20", .... @"15:05"];
Run Code Online (Sandbox Code Playgroud)
因此阵列从8:06到15:05以1分钟为增量.我想要的只是我无法弄清楚该怎么做,是一个新的阵列,但是从前5个多次开始,即:8:10然后继续增加5分钟到15:05,所以最终数组的NSLog将是这样的:
8:10, 8:15, 8:20, 8:25, ...., 10:45, 10:50, 10:55, 11:00, 11:05, ...., 14:55, 15:00, 15:05
Run Code Online (Sandbox Code Playgroud)
所以任何想法???
好吧,我遇到一个nsarray的问题,它是从nsdictionary添加重复的对象.
情况是这样的:我有一个带有一系列字典的plist文件.每个字典都有'codigo'和'var'.
我做的是我检查每个'var'值是否为<0,如果它是'codigo','var'将使用NSAttributedStrings获得颜色.
当我遍历数组并将评估的'var'添加到新数组中时,问题就来了.我在最终的数组中得到重复的对象.
编辑:解决方案源自xlc0212的答案和聊天帮助:
_timer = [NSTimer scheduledTimerWithTimeInterval:0.020 target:self
selector:@selector(time:) userInfo:nil repeats:YES];
NSDictionary *redAttrs = @{NSForegroundColorAttributeName:[UIColor redColor]};
NSDictionary *greenAttrs = @{NSForegroundColorAttributeName:[UIColor colorWithRed:0.118 green:0.506 blue:0.000 alpha:1.000]};
NSDictionary *orangeAttrs = @{NSForegroundColorAttributeName:[UIColor orangeColor]};
NSString *stringUm = @"";
NSString *stringDois = @"";
NSString *stringTres = @"";
arrayAtivos = [[NSMutableOrderedSet alloc] init];
NSDictionary *item = [[NSDictionary alloc]init];
for (item in array){
NSString *alfa = [item objectForKey:@"var"];
float fltNumber = [alfa floatValue];
if (fltNumber < 0) {
stringUm = [NSString stringWithFormat:@"%@ %.2f ",[item objectForKey:@"codigo"], fltNumber]; …Run Code Online (Sandbox Code Playgroud) 嘿家伙我正在尝试在滚动表时从UITableView更改默认taxtLabel的alpha但我收到此错误:
Cannot invoke 'animateWithDuration' with an argument list of type '(FloatLiteralConvertible, animations: () -> () -> $T2)'
Run Code Online (Sandbox Code Playgroud)
我的代码是这样的:
override func scrollViewDidScroll(scrollView: UIScrollView) {
for cell in tableView.visibleCells() {
UIView.animateWithDuration(0.5, animations: {
cell.textLabel??.alpha = 0.0
})
}
}
Run Code Online (Sandbox Code Playgroud) swift ×4
ios ×3
objective-c ×3
ios8 ×2
nsarray ×2
uitextfield ×2
core-data ×1
currency ×1
duplicates ×1
endianness ×1
ios5 ×1
nsdata ×1
uisearchbar ×1