Tag: cocoa touch

如何在iOS中检查CLLocation的有效性

如何检查iOS中的CLLocation有效性? 其实这是我的情况, 我只是创build一个新的地图 mapView = [[MKMapView alloc] initWithFrame:CGRectMake(10, 30, 300, 380)]; mapView.showsUserLocation = YES; [mapView setDelegate:self]; 然后我想检查用户位置的有效性 mapView.userLocation.location 由于我在使用用户位置时遇到此错误 'NSInvalidArgumentException', reason: 'Invalid Coordinate -180.00000000, -180.00000000' 在此先感谢〜

UIColor colorWithRed:green:blue:alpha:总是返回白色,除非一个参数是0

我在用 [UIColor colorWithRed:136 green:155 blue:218 alpha:1.0]; 改变我的表格视图单元格的背景颜色。 但由于某种原因,背景只是保持白色。 如果我尝试 [UIColor colorWithRed:0 green:155 blue:218 alpha:1.0]; 颜色改变。 这对我来说没有意义。 任何build议或提示?

使用点语法设置保留属性时使用autorelease?

我看到在一些示例代码中使用autorelease 。 我不熟悉需要的情况。 例如,如果我创build一个注释对象 头文件 @interface someViewController: UIViewController { Annotation *annotation; } @property (nonatomic, retain) Annotation *annotation; @end 实施文件 @implementation someViewController @synthesize annotation @end 问题:如果我像这样初始化实现文件中的注释对象,是否是正确的方法? self.annotation = [[Annotation alloc] initWithCoordinate:location]; 我需要为此设置autorelease吗? 或者我可以按照正常的方式做,并在dealloc方法中添加发行版?

以编程方式从NSCachesDirectory中删除文件

如果我在应用程序中NSCachesDirectory编程方式下载NSCachesDirectory中的文件,是否也可以通过编程方式删除这些文件?

AVAudioRecorder / AVAudioPlayer – 追加logging到文件

有什么方法可以录制到audio文件的末尾? 我们不能只是暂停logging而不是停止logging,因为用户需要能够稍后回到应用程序,并添加更多的audio到他们的logging。 目前,audio以NSDataforms存储在CoreData中。 NSData的AppendData不起作用,因为生成的audio文件仍然报告它只与原始数据一样长。 另一种可能性是将原始的audio文件和新的audio文件一起,并将它们连接成一个audio文件,如果有什么办法的话。

如何在Swift中存档和取消存档自定义对象? 或者如何将自定义对象保存到Swift中的NSUserDefaults?

我有一堂课 class Player { var name = "" func encodeWithCoder(encoder: NSCoder) { encoder.encodeObject(name) } func initWithCoder(decoder: NSCoder) -> Player { self.name = decoder.decodeObjectForKey("name") as String return self } init(coder aDecoder: NSCoder!) { self.name = aDecoder.decodeObjectForKey("name") as String } init(name: String) { self.name = name } } 我想序列化并保存到用户的默认值。 首先我不确定如何正确编写编码器和解码器。 所以对于init我写了两个方法。 当我尝试执行此代码: func saveUserData() { let player1 […]

为什么我不能注册我的iOS应用程序来处理图像文件types?

我有一个注册图像文件types到我的应用程序的问题。 我试着把下面的代码添加到我的plist中,但没有任何反应。 <key>CFBundleDocumentTypes</key> <array> <dict> <key>CFBundleTypeName</key> <string>Scary Bug Document</string> <key>LSHandlerRank</key> <string>Alternate</string> <key>CFBundleTypeRole</key> <string>None</string> <key>LSItemContentTypes</key> <array> <string>public.image</string> </array> </dict> </array> 我注意到,我可以注册其他文件types,如文本(更改public.image public.text ),但它不会与图像(“打开..”菜单不显示我的应用程序)。 有什么可能导致这个,我怎么能解决它?

ios UTF8编码从nsstring

我正在收到一个没有正确编码的nsstring,比如“mystring%201,其中必须是”mystring 1“,我怎样才能replace所有可以被解释为UTF8的字符?我读了很多post,但没有一个完整的解决scheme。注意,nsstring已经被编码错了,我不问如何编码字符序列,谢谢。

在iOS7上区分屏幕locking和主页button

我需要在applicationDidEnterBackground做一些事情。 但我需要区分哪些用户行为导致“进入背景”:屏幕locking或主页按下button。 我正在使用这个代码,这是从这篇文章 – 如何区分iOS5上的屏幕locking和主页button? : UIApplicationState state = [application applicationState]; if (state == UIApplicationStateInactive) { NSLog(@"Sent to background by locking screen"); } else if (state == UIApplicationStateBackground) { NSLog(@"Sent to background by home button/switching to other app"); } 它在iOS6上正常工作。 但在iOS7(设备和模拟器),我总是得到UIApplicationStateBackground ,无论用户点击主页还是lockingbutton。 有人有什么可能导致这个问题的想法吗? iOS 7更新到多任务后台处理? 或者我的应用程序的一些设置(我的应用程序的背景模式closures)? 还有其他解决scheme吗?

尝试从主线程或Web线程以外的线程获取Weblocking。 现在崩溃了

bool _WebTryThreadLock(bool), 0x8053ce0: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now… 我得到这个错误。 今天我第一次发现了这个错误,显示了密码对话框,并且alertview显示在顶部,直到viewWillAppear显示视图时才会出现。 这一切似乎工作得很好,当我有一天发展这一点。 不知道为什么线程锁已经丢失,怎么实现呢?