nsstring

% sign in string objective c

本小妞迷上赌 提交于 2019-12-08 20:16:31
问题 i am wondering how i do a % sign within a NSString, i have tried \% and \\% 回答1: Try %% . Short question, short answer. :) 回答2: just put %% to use a % sign within objective c. 回答3: There's no special escaping required for percent signs. Just write: str = @"Rate of Return (in %)"; ...unless you mean NSString stringWithFormat . But your question doesn't say so. 回答4: According to Apple's 'String Format Specifiers' page, simply use %% . For example: NSString * aString = @"50%%"; Reference: http:/

File Name NSString adds unnecessary %20 in space

扶醉桌前 提交于 2019-12-08 19:55:14
问题 SOLVED (Thanks Regexident) I have an app that passes the file path of a PDF to a custom -(id)init init method. It is added to the table and when it is selected, it calls the else statement for a non existent file: - (void) gridView:(AQGridView *)gridView didSelectItemAtIndex:(NSUInteger)index { NSLog (@"Selected theArgument=%d\n", index); UIViewController *viewController = [[[UIViewController alloc]init]autorelease]; { //if file is built-in, read from the bundle if (index <= 3) { // first

iOS与js交互(WebView+WKWebView)

心已入冬 提交于 2019-12-08 19:40:45
需求:1点击js登入按钮将用户账号和密码传给移动端 2将客户端的token传给html端 据我了解有以下几种方法 1:webview的javascriptCore 2:webkit 3:url拦截 4:第三方库 我用的是1和2 理论:js与oc相互调用并且传值 我们可以理解成河2边需要送东西的过程 我们需要在js和oc之间搭建一个桥梁而jsexport就是这做桥梁,有了桥梁以后在2端传值我们还需要一个对象(快递员) 就好比现实中js在桥的一段,而移动端在桥的这一边现在他们需要给彼此送东西那么就需要一个快递员(对象) ---------------------------------------------------------- 第一种WebView+ javascriptCore 第一步搭建2端之间桥梁javascriptcore 1)导入javascriptCore Build phass->link binary with libraries 添加头文件 #import <JavaScriptCore/JavaScriptCore.h> 2)初始化桥梁 @property(nonatomic,strong)JSContext *jsContext; 在web的webViewDidFinishLoad:代理方法中 self.jsContext = [self

WKWebView替换WebView体会总结

我们两清 提交于 2019-12-08 19:36:34
一.引言 最近应公司要求,把项目里用到的UIWebView全都用WKWebView替换掉。于是就去研究了WKWebview,加上在使用中遇到的一些问题加以总结,如有不足之处,还望指出,本人将会加以修改。 UIWebView 自iOS2就有, WKWebView 从iOS8才有,毫无疑问 WKWebView 将逐步取代笨重的 UIWebView 。通过简单的测试即可发现 UIWebView 占用过多内存,且内存峰值更是夸张。 WKWebView 网页加载速度也有提升,但是并不像内存那样提升那么多。下面列举一些其它的优势: 更多的支持HTML5的特性 官方宣称的高达60fps的滚动刷新率以及内置手势 Safari相同的JavaScript引擎 将UIWebViewDelegate与UIWebView拆分成了14类与3个协议( 官方文档说明 ) 另外用的比较多的,增加加载进度属性: estimatedProgress 缺点 : WKWebView 不支持缓存 和 NSURLProtocol 拦截了 二、UIWebView使用说明 1 举例:简单的使用 UIWebView 使用非常简单,可以分为三步,也是最简单的用法,显示网页 // 1. 创建 webview ,并设置大小, "20" 为状态栏高度 UIWebView *webView = [[UIWebView alloc]

App Transport Security on Safari Extension

泪湿孤枕 提交于 2019-12-08 18:47:57
问题 My App extension need to open URL from many websites. I do as following: for (NSExtensionItem *item in self.extensionContext.inputItems) { for (NSItemProvider *itemProvider in item.attachments) { if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeURL]) { [itemProvider loadItemForTypeIdentifier:(NSString *)kUTTypeURL options:nil completionHandler:^(NSURL *url, NSError *error) { NSLog(@"URL: %@",url); I can get the URL, but at this point I got this error: App Transport

List of supported attribute keys for NSString.sizeWithAttributes?

℡╲_俬逩灬. 提交于 2019-12-08 17:37:45
问题 iOS 7 uses NSString::sizeWithAttributes to calculate the size of the bounding box of an NSString given an NSDictionary of attributes. However, I can't find a resource that lists all the enumerated keys available for use in that NSDictionary . The NSString UIKit Additions Reference says that These are the same attributes that can be applied to an NSAttributedString object but doesn't list them, and they're not listed in the NSAttributedString documentation either. Also: of the available

NSString – static or inline? Is there any performance gains?

人走茶凉 提交于 2019-12-08 15:53:49
问题 Is there any performance gain if I write - (NSString *)helloStringWithName:(NSString *)name static NSString *formatString = @"Hello %@!"; return [NSString stringWithFormat:formatString, name]; } instead of - (NSString *)helloStringWithName:(NSString *)name return [NSString stringWithFormat:@"Hello %@!", name]; } ?? If I were to guess I would think that the latter one is created and autoreleased each time the code is running, but I guess the compiler is smart enough to know what do here.. 回答1:

Check NSString is encoded or not

两盒软妹~` 提交于 2019-12-08 13:56:06
问题 How to detect a NSString which is already encoded or not.? I'm encoding my string like below. Before encoding this i just want to verify weather this [product url] is already encoded or not. NSString *encodedUrlString=[[product url] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 回答1: You could try decoding the string and see if the original string and the decoded string are the same or not. If they are the same then it wasn't encoded yet. NSString *original = product.url;

getting 0.0000 when converting NSString value to float

♀尐吖头ヾ 提交于 2019-12-08 13:43:17
问题 In my application, i tried to convert NSString value to float using NSString *value = [dict objectForKey:@"student_Percentage"]; float f = [value floatValue]; But I'm getting the value of f as 0.00000. I tried with NSNumberFormatter, NSNumber... but still get 0.00000. 回答1: floatValue returns 0.0 if the receiver doesn’t begin with a valid text representation of a floating-point number. [dict objectForKey:@"student_Percentage"] value should be like 8.9. Remove double quotes from your string.

Displaying 'special' characters from other encodings in UILabel or similar

限于喜欢 提交于 2019-12-08 13:15:12
问题 I'd like to be able to simulate a terminal on my iPhone to play games like Nethack using the primitive graphics I enjoyed on a real DEC terminal. Nethack allows selection of DECgraphics for vt-compatible terminals or IBMGraphics for codepage 437 support. I know that these special graphics characters are generated by strings sent to the terminal (vt100.net has a huge amount of information including the terminal manuals and test programs). I can receive and interpret those strings but I need to