nsstring

How can I pass an NSString from one View Controller to another?

强颜欢笑 提交于 2019-12-22 18:51:57
问题 I made a very simple storyboard based project with two View Controllers. I want to simply access a string declared in VC1 from VC2. The second VC should then display the text in a textfield upon the press of a button. I do not want to use delegation , a separate class for global data or global variables and Extern . Instead, I read that it was easy to achieve variable sharing using a reference to one VC in the other. For my code shown below, XCode didn't complain, however my problem is this:

How can I pass an NSString from one View Controller to another?

青春壹個敷衍的年華 提交于 2019-12-22 18:51:12
问题 I made a very simple storyboard based project with two View Controllers. I want to simply access a string declared in VC1 from VC2. The second VC should then display the text in a textfield upon the press of a button. I do not want to use delegation , a separate class for global data or global variables and Extern . Instead, I read that it was easy to achieve variable sharing using a reference to one VC in the other. For my code shown below, XCode didn't complain, however my problem is this:

Different kind of UTF8 decoding in NSString

不羁岁月 提交于 2019-12-22 18:36:45
问题 I have searched a lot about UTF8 decoding, but not found the answer yet. I receive an UTF-8 decode NSString from my NSXMLParser: NSString *tempString = @"Test message readability is óké"; In someway I can't find the way to change this encoded text to: Test message readability is óké I could tell all the options I tried but I don't think that should be necessary. Could please some help? Thnx! 回答1: The NSXMLParser will treat the text using the character encoding that the XML specifies. I

Checking NSString for balanced delimiters

怎甘沉沦 提交于 2019-12-22 18:26:29
问题 My input ( NSString )can be ("text") , {("text")} or (“text”){{“text”}} . In all those cases, I have to make sure that an opening delimiter ( { ) gets its own closing delimiter ( } ). For example, {{“text”}) should be marked as an error. I'm trying NSScanner to accomplish this, and also tried reversing the string and comparing each character looking for its opposite, but've been having some trouble. What would be the best approach? This is the latest way I tried going: NSMutableString

IOS实现多媒体音频之音乐播放器

Deadly 提交于 2019-12-22 13:59:14
  随着智能手机市场越来越活跃,相应的app也变得五彩缤纷,各式各样,让你的app更吸引人多媒体技术不可避免。通过对音频和视频等控制让你的app更加丰富多彩,今天和大家一起研究下基本的音频使用。本文只提供部分代码,如果疑问可以 下载源码 查看。   功能主界面如下: 首先引入音频播放框架    2、通过故事版搭建界面,由于该步骤很简单,这里不讲解。如图所示: 3、定义变量存放数据,并将文件中歌曲信息封装成模型放入数组 /** 加载歌曲数据*/ @property(nonatomic,strong) NSMutableArray * dataArray; /** 保存cell数据控制颜色*/ @property(nonatomic,strong) NSMutableArray * cellArray; /** 当前正在播放的音乐*/ @property(nonatomic,strong) JRPlayerViewController * playerVC; /** 上次播放的音乐*/ @property(nonatomic,strong) NSIndexPath * front; #pragma mark - 加载数据 - (void) _loadData{ NSString * path=[[NSBundle mainBundle] pathForResource:@"Musics

How to gzip NSData with zlib?

随声附和 提交于 2019-12-22 13:55:47
问题 I want to use zlib because I'm assuming it's the best & fastest way to gzip NSData . But, is there a better way? If not, which version of the zlib library should I link to in Xcode: libz.dylib, libz.1.dylib, libz.1.1.3.dylib, or libz.1.2.5.dylib? Please provide a code example of how to us zlib to convert NSData *normalHTTPBody into NSData gzippedHTTPBody 回答1: Yes, zlib is what is used to gzip data. I know of no better way. As for speed, you can select the compression level to optimize speed

使用Objective-C 输出字符串"HelloWorld"

大兔子大兔子 提交于 2019-12-22 11:44:40
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 使用Objective-C 输出字符串"HelloWorld"步骤如下! 创建Objective-C的第一个工程 HelloWorld Objective-C中的字符串 Hello World main.m^程序的入口文件^ //// main.m// HelloWorld//// Created by lewis on 9/7/15.// Copyright (c) 2015 lewis. All rights reserved.//#import <Foundation/Foundation.h>int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... NSLog(@"Hello, World!"); } return 0; } 那么现在我们来分析一下整个 main.m 文件的结构 注释部分 在注释部分,大家应该都没有问题,跟c、c++的注释风格很相近; 导入头文件部分 #import 关键字的功能,类似于C、C++语言中的 #include 关键字,但是功能不是完全相同; 主函数实现部分 int main(int argc, const char * argv[]) 整个程序的入口函数

Get selection (highlighted text) string from NSTextView Objective-C

不打扰是莪最后的温柔 提交于 2019-12-22 11:18:39
问题 How can I get the selected text's string from a NSTextView as an NSString ? Your help is greatly appreciated. 回答1: Since NSTextView is a subclass of NSText, you can use NSText instance methods to figure out the selected string like so: NSString *selected = [[myTextView string] substringWithRange:[myTextView selectedRange]]; 回答2: An NSText can have more than only one selection. Check it out with TextEditapp: select a string with the mouse while pressing CMD. So you can select as many strings

NSString to JSON string

风流意气都作罢 提交于 2019-12-22 11:16:09
问题 I have a NSString with below format .Currently it is not a valid JSON string .I want to change it as a JSON string and store it in an NSArray . This is my NSString. [, {"Agent":" Visitor", "Time":"03:18 AM", "Message":"Msg from : file:///Users/satheesanop/Desktop/something.htmlIP Address : 182.72.139.142Country : IndiaCity : MadrasRegionName : Tamil N?duBrowser : Chrome 22OS : Mac", }, {"Agent":" agent name", "Time":"03:21 AM", "Message":"Thank you for contacting us.How may i help you ?", },

Decoding partial UTF-8 into NSString

感情迁移 提交于 2019-12-22 10:48:45
问题 While fetching a UTF-8 -encoded file over the network using the NSURLConnection class, there's a good chance the delegate's connection:didReceiveData: message will be sent with an NSData which truncates the UTF-8 file - because UTF-8 is a multi-byte encoding scheme, and a single character can be sent in two separate NSData In other words, if I join all the data I get from connection:didReceiveData: I will have a valid UTF-8 file, but each separate data is not valid UTF-8 (). I do not want to