• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

iOS 开发百问(10)

php 搞代码 3年前 (2022-01-22) 25次浏览 已收录 0个评论

121、如何将字典/数组转换为字符串?

NSString* id2json(id dicOrArr){NSError *error;NSData *jsonData =[NSJSONSerializationdataWithJSONObject:dicOrArroptions:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about thereadability of the generated stringerror:&error];if (! jsonData) {DLog(@"Got an error:%@", error);return nil;} else {NSString *jsonString =[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];return jsonString;}}

122、Xcode 6.1 GM,AudioToolbox 无法使用
通常,我们在程序中习惯用 AudioToolbox 来播放较短的声音效果,例如这段代码,在 Xcode 6.0 中是可用的,但在 Xcode 6.1 GM 上来4源gaodaimacom搞#代%码*网搞代gaodaima码会导致一个编译错误:

func playSystemSound(soundName:String){// Tink.cafletsoundPath:String="/System/Library/Audio/UISounds/"+soundNamevar soundID:SystemSoundID = 0ifNSFileManager.defaultManager().fileExistsAtPath(soundPath) {let soundURL =NSURL(fileURLWithPath: soundPath)AudioServicesCreateSystemSoundID(soundURL as CFURL, &soundID)AudioServicesPlaySystemSound(soundID)}}

只需将 AudioServicesCreateSystemSoundID(soundURL as CFURL, &soundID) 替换为:
AudioServicesCreateSystemSoundID(soundURL, &soundID)
123、升级为 Yosemite 后,Xcode6 无法运行模拟器
升级为 Yosemite 后,Schema 中的所有模拟器消失,如下图所示,模拟器一栏仅剩下 iOS Device :

此时,App 无法在模拟器上运行。
解决方法为,打开模拟器(方法:Xcode -> Open Developer Tool -> iOS ),此时会弹出一个 Unable to determine device 的错误,不用管,点击 OK。在模拟器菜单,Hardware -> Device ->Manage Devices…,弹出设备列表。点击左下角的 + 按钮,添加所需要的模拟器,然后点击 Create即可,如下图所示:

124、集成Alamofire时出现错误:only supported on iOS 8.0 andlater
将Alamofire的deployment target设置为和主项目的一样。

125、错误:must register a nib or a class for the identifier
当使用编程方法构建UITableViewCell时,需要注册该UITableViewCell的xib。在 viewDidLoad 方法中加入下句:

[self.yourTableViewName registerNib:[UINibnibWithNibName:@"YourNibName" bundle:nil]forCellWithReuseIdentifier:@"YourIdentifierForCell"];

如果UITableViewCell未使用xib,但该UITableViewCell有自定义的.m/.h文件,则使用下句替代:

[self.tableView registerClass:[UITableViewCell class]forCellReuseIdentifier::@"Cell"];

126、错误Undefined symbols for architecture armv7
如果你在真机调试出现这个错误,在模拟器下没有这个错误。说明有某个lib库只有x86版本,而缺少armv7/armv6版本。查看错误所指向的库,用lipo –info 命令检查该.a文件的二进制信息。
如果缺少armv6/armv7版本的.a文件,请重新编译一个armv7/armv6的.a文件添加到工程中。
还可以用lipo –create –output命令将两个版本的.a文件融合成一个通用版.a文件放到工程中。
此外,可能还需要检查Library Search Path设置,看.a文件的路径指向是否正确。
127、错误Type 'String' does not conform to protocol 'IntervalType'
当switch语句中对String? 进行匹配时出现此错误。例如:

switch item.name {case "到达现场时间":cellItems.append(item)default:break}

修改为如下语句可解决此错误:

if let name = item.name{switch name {case "到达现场时间":cellItems.append(item)default:break}}

128、pod update时经常出现错误:Attempt to read nonexistent folder
cocoapod服务器被墙了,请使用代理或者VPN(推荐VPN)。

129、ViewController类声明出现错误:initializer 'init(coder:)'must be provided by a subclass of UIViewController
在你的ViewController中有某个属性声明时未赋予初值,而且也没有标记为可空。例如 varkPickerViewSize:CGSize,可修改为var kPickerViewSize:CGSize?即可消除此错误

130、Swift中如何取得Dictionary的所有key?
在NSDicationary中可以使用allKeys属性,在Dictionary中则使用keys属性:

let array:[String] = [String](dictionary.keys)


以上就是iOS 开发百问(10)的内容,更多相关内容请随时关注我们网站!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:iOS 开发百问(10)

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址