Questions tagged «nsrange»

13
NSRange到Range <String.Index>
如何在Swift中转换NSRange为Range&lt;String.Index&gt;? 我想使用以下UITextFieldDelegate方法: func textField(textField: UITextField!, shouldChangeCharactersInRange range: NSRange, replacementString string: String!) -&gt; Bool { textField.text.stringByReplacingCharactersInRange(???, withString: string)
258 nsstring  swift  ios8  nsrange 

11
Swift Range的NSRange?
问题:我在使用使用Range的Swift String时,NSAttributedString需要一个NSRange let text = "Long paragraph saying something goes here!" let textRange = text.startIndex..&lt;text.endIndex let attributedString = NSMutableAttributedString(string: text) text.enumerateSubstringsInRange(textRange, options: NSStringEnumerationOptions.ByWords, { (substring, substringRange, enclosingRange, stop) -&gt; () in if (substring == "saying") { attributedString.addAttribute(NSForegroundColorAttributeName, value: NSColor.redColor(), range: substringRange) } }) 产生以下错误: 错误:“范围”不可转换为“ NSRange” attributedString.addAttribute(NSForegroundColorAttributeName,值:NSColor.redColor(),范围:substringRange)
175 ios  macos  swift  nsrange 

7
Swift中的ChangeCharactersInRange应该如何工作?
我正在使用shouldChangeCharactersInRange作为使用即时类型搜索的方式。 但是我有一个问题,在文本字段实际更新之前应该调用shouldChangeCharactersInRange: 在目标C中,我使用以下方法解决了这个问题: -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSString * searchStr = [textField.text stringByReplacingCharactersInRange:range withString:string]; return YES; } 但是,我尝试用Swift编写此代码: func textField(textField: UITextField!, shouldChangeCharactersInRange range: NSRange, replacementString string: String!) -&gt; Bool { let txtAfterUpdate:NSString = self.projectSearchTxtFld.text as NSString txtAfterUpdate.stringByReplacingCharactersInRange(range, withString: string) self.callMyMethod(txtAfterUpdate) return true } 在获得值之前,该方法仍会被调用?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.