nsstring

How to send an NSString to another view controller

人走茶凉 提交于 2020-01-28 12:34:11
问题 I have an IBAction that when triggered calls another method in a different view controller ( APICallsViewController). I'm looking to also send that method an NSString (message) here's my IBAction with the push to the APICallsViewController and also the NSString message. My question might be how do I grab the contents of that NSString in the other view controller's method. thanks for any help -(IBAction) someMethod{ APICallsViewController *apiViewController = [[APICallsViewController alloc]

How to send an NSString to another view controller

丶灬走出姿态 提交于 2020-01-28 12:30:09
问题 I have an IBAction that when triggered calls another method in a different view controller ( APICallsViewController). I'm looking to also send that method an NSString (message) here's my IBAction with the push to the APICallsViewController and also the NSString message. My question might be how do I grab the contents of that NSString in the other view controller's method. thanks for any help -(IBAction) someMethod{ APICallsViewController *apiViewController = [[APICallsViewController alloc]

iOS NSDate与NSString之间的相互转换

青春壹個敷衍的年華 提交于 2020-01-28 09:15:09
假如我们需要把当前的时间当成一个字符串作为一张图片的名字的话,就需要把当前的时间NSDate类型的数据转换成NSString类型。 又或者在网络请求的时候,我们在网络上的到时间是一个字符串但是在本地就需要输出NSDate类型的数据。 所以提供两个方法 第一个是将 NSDate类型的数据转换成NSString类型的数据 , 第二个是 将NSString类型的数据转换成NSDate类型的数据 1.NSDate -> NSString //获取当前时间 NSDate *date = [NSDate date]; //设置日期格式 NSDateFormatter* formatter1 = [[NSDateFormatter alloc] init]; [formatter1 setDateFormat:@"yyyyMMddHHmmss"]; //变为数字 NSString* str = [formatter1 stringFromDate:date]; NSLog(@"dateString = %@",str); 2.NSString -> NSDate //时间字符串 NSString *str = @"20150806070733"; //规定时间格式 NSDateFormatter* formatter = [[NSDateFormatter alloc] init];

iOS中FMDB的使用【单例】

我怕爱的太早我们不能终老 提交于 2020-01-27 09:50:28
DYDB.h Objective-C 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #import <Foundation/Foundation.h> #import <FMDB/FMDatabase.h> @interface DYDB : NSObject { } @property ( nonatomic , readonly ) FMDatabase * database ; + ( DYDB * ) sharedDB ; - ( FMDatabase * ) connect ; - ( void ) clearDB ; @end DYDB.m Objective-C 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 #import “DYDB.h” #define kDYDBObvName @”dyobv.sqlite” @implementation DYDB static DYDB * _sharedDB ; + ( DYDB * ) sharedDB { if ( ! _sharedDB ) { _sharedDB = [[

iOS设计中字符串NSString与int及float之间的转换

♀尐吖头ヾ 提交于 2020-01-27 04:18:49
在oc语言中,字符串使用NSString定义成一个用于保存字符串的对象变量,而数字则使用原始类型float、int等数据类型定义成一个变量,这是一个原生态的变量。 这两种变量之间在开发时会需要相互转化。 1、数字转换为字符串 int num1=8888; NSString *String = [NSString stringWithFormat:@"%d",num1]; float num2=2158.55; NSString *String = [NSString stringWithFormat:@"%f",num2]; 2、字符串拼接 NSString *tempA = @"123"; NSString *tempB = @"456"; NSString *newString = [NSString stringWithFormat:@"%@%@",tempA,tempB]; 3、字符串转int类型 int intString = [newString intValue]; 4、int转字符串 NSString *stringInt = [NSString stringWithFormat:@"%d",intString]; 5、字符串转float float floatString = [ newString floatValue]; 6、float转字符串

定位于地图小程序

北城以北 提交于 2020-01-26 19:37:56
导读: 最近做了一个小程序模仿GPS,实现的基本功能有定位,地点查找,与导航等等,主要涉及到编码与反编码,(还有就是系统自己的)听着很麻烦,其实当自己理解了发现也不是那么难。废话也不多说。涉及到的函数根据代码来介绍。 我们先看看Main.storyboard,下图所示,结构非常简单,几个button,text,一个mapview。 介绍一下这个几个按钮的作用: 编码:就是把我们的输入的地点名字来获得它对应的经纬度以及详细信息。 反编码:就是把经纬度进行解析,获取这个经纬度对应的一些信息比如(城市,街道,乡。省)。 我的位置:定位到自己的位置。 路线(导航):根据自己的位置和搜索的地名来设计路线。 在我们写代码前我们还需要做几件事: 1.授权:打开工程中info.plist属性列表文件,添加2个键Privacy - Location Usage Description和Privacy - Location Always Usage Description。 2添加2个框架:如下图 在这里介绍一下这2框架,为什么我们要用到它: CoreLocation框架: 在IOS中,定位服务API主要使用的就是CoreLocation框架,在我们编制定位程序时,就要用到它的3个类。 1)CLLocationManager:他的作用在于可以为我们提供位置的一些信息(经纬度)

Convert UTF-8 encoded NSData to NSString

帅比萌擦擦* 提交于 2020-01-26 05:28:32
问题 I have UTF-8 encoded NSData from windows server and I want to convert it to NSString for iPhone. Since data contains characters (like a degree symbol) which have different values on both platforms, how do I convert data to string? 回答1: If the data is not null-terminated, you should use -initWithData:encoding: NSString* newStr = [[NSString alloc] initWithData:theData encoding:NSUTF8StringEncoding]; If the data is null-terminated, you should instead use -stringWithUTF8String: to avoid the extra

Convert UTF-8 encoded NSData to NSString

微笑、不失礼 提交于 2020-01-26 05:27:17
问题 I have UTF-8 encoded NSData from windows server and I want to convert it to NSString for iPhone. Since data contains characters (like a degree symbol) which have different values on both platforms, how do I convert data to string? 回答1: If the data is not null-terminated, you should use -initWithData:encoding: NSString* newStr = [[NSString alloc] initWithData:theData encoding:NSUTF8StringEncoding]; If the data is null-terminated, you should instead use -stringWithUTF8String: to avoid the extra

iOS 的组件化开发

六月ゝ 毕业季﹏ 提交于 2020-01-26 03:23:35
在一个APP开发过程中,如果项目较小且团队人数较少,使用最基本的MVC、MVVM开发就已经足够了,因为维护成本比较低。 但是当一个项目开发团队人数较多时,因为每个人都会负责相应组件的开发,常规开发模式耦合会越来越严重,而且导致大量代码冲突,会使后期维护和升级过程中代码“牵一发而动全身”,额外带来很大的工作量,并且会导致一些潜在的BUG。 在这时,组件化开发就派上很大用场了,所谓的组件化开发,就是把APP根据业务拆分为各独立的组件,各个组件相互写作,组成完整的APP。 一、各组件的引入 关于组件的拆分,就根据具体项目进行拆分,假如APP被拆分了AModule、BModule、CModule,那么,应该如何引入这些组件呢?你可能会想到APP的入口AppDelegate。在平时开发中,AppDelegate中往往初始化了好多组件,比如推送、统计等组件,这样就会导致AppDelegate的臃肿。 所以,我们可以增加一个 ModuleManager ,专门用来初始化各组件。 首先增加一个 ModuleProtocol : #import <Foundation/Foundation.h> @import UIKit; @import UserNotifications; @protocol ModuleProtocol <UIApplicationDelegate,

第13条:用“方法调配技术”调试“黑盒方法”

为君一笑 提交于 2020-01-26 00:26:37
  本条要点:(作者总结) 在运行期,可以向类中新增或替换选择子所对应的方法实现。 使用另一份实现来替换原有的方法实现,这道工序叫做“方法调配”,开发者常用此技术向原有实现中添加新功能。 一般来说,只有调试程序的时候才需要在运行期修改方法实现,这种做法不宜滥用。   第 11 条中解释过: Objective-C 对象收到消息之后,究竟会调用何种方法需要在运行期才能解析出来。那你也许会问:与给定的选择子名称相对应的方法是不是也可以在运行期改变呢?没错,就是这样。若能善用此特性,则可发挥出巨大优势,因为我们既不需要源代码,也不需要通过继承子类来覆写方法就能改变这个类本身的功能。这样一来,新功能将在本类的所有实例中生效,而不是仅限于覆写了相关方法的那些子类实例。此方案经常称为 “方法调配”(method swizzling)(也叫做“方法混合”、“方法调和”)。   类的方法列表会把选择子的名称映射到相关的方法实现之上,使得“动态消息派发系统”能够据此找到应该调用的方法。这些方法均以函数指针的形式来表示,这种指针叫做 IMP,其原型如下: 1 id (*IMP)(id, SEL, ...)   NSString 类可以响应 lowercaseSting、uppercaseString、capitalizedString 等选择子,这个张映射表中的每个选择子都映射到了不同的 IMP 之上