我已经阅读了很多有关是否URLForUbiquityContainerIdentifier:应该在主线程之外调用的相互矛盾的信息.在很多Apple的文档中,他们总是在主线程上调用这个方法.但是,我还读到,调用此方法可能会阻塞很长时间.
每个人的想法是什么?在主线程中调用它并不担心或是,总是在另一个线程中进行此调用?
我正在添加两个由属性存储的子视图到我的视图中.将子视图添加到我的视图时,在调用我的setup方法后,子视图似乎被释放.最终结果是视图永远不会显示.现在,如果我改变我的属性,strong而不是weak保留对视图的引用,它们现在显示在屏幕上.那么这里发生了什么?为什么addSubview:并insertSubview:没有保留子视图?请参阅以下代码:
顺便说一下,我正在使用带有ARC的iOS5(因此强弱的东西)
#import "NoteView.h"
@interface NoteView() <UITextViewDelegate>
@property (weak, nonatomic) HorizontalLineView *horizontalLineView; // custom subclass of UIView that all it does is draw horizontal lines
@property (weak, nonatomic) UITextView *textView;
@end
@implementation NoteView
@synthesize horizontalLineView = _horizontalLineView;
@synthesize textView = _textView;
#define LEFT_MARGIN 20
- (void)setup
{
// Create the subviews and set the frames
self.horizontalLineView = [[HorizontalLineView alloc] initWithFrame:self.frame];
CGRect textViewFrame = CGRectMake(LEFT_MARGIN, 0, self.frame.size.width, self.frame.size.height);
self.textView = [[UITextView …Run Code Online (Sandbox Code Playgroud) 在飞行模式或任何其他网络访问不可用的状态下,对NSFileManager的调用是否会URLForUbiquityContainerIdentifier:返回nil?
对此的后续问题是:如果对URLForUbiquityContainerIdentifier:DOES的调用不返回nil而是在网络访问不可用时返回有效URL,这是一种离线访问基于云的文档的方法吗?
apple docs声明,如果未配置或未启用iCloud,则返回nil.它没有提到如果网络访问不可用会发生什么.
我会自己测试一下,但是根据我的理解,我必须在实际设备上进行测试,并且此时我无法在设备上进行测试.谢谢!
我目前正在通过执行以下操作来执行卷曲动画:
CATransition *animation = [CATransition animation];
animation.type = @"pageCurl";
animation.subtype = kCATransitionFromTop;
animation.fillMode = kCAFillModeForwards;
animation.duration = 1;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
[[self.view.window layer] addAnimation:animation forKey:nil];
Run Code Online (Sandbox Code Playgroud)
此动画将简单地执行页面卷曲动画,但最终您会看到与开始时相同的视图。从未发生过真正的转变。
现在使用动画块我知道你可以做一些事情来达到以下效果:
[UIView transitionFromView:self.view
toView:aNewView // a view to transition to
duration:1
options:UIViewAnimationTransitionCurlUp|UIViewAnimationOptionCurveEaseIn
completion:NULL];
Run Code Online (Sandbox Code Playgroud)
但是,使用动画块您正在过渡到一个新视图,aNewView这与上面的 CATransition 动画不同,后者重用相同的视图(从未发生真正的过渡)。动画块的问题在于您必须实际创建要转换的新视图,在我的情况下这很麻烦,因为视图相当复杂,我宁愿不创建 UIView 子类。
有没有办法使用动画块执行上述 CATransition 动画,同时解决必须重建视图或创建自定义子类的困难?
在界面构建器中,在支柱和弹簧检查器中有一个标记为原点的控件.这样做以及为什么为一个对象更改它会为所有对象更改它?

据我所知,据我所知,它对框架矩形原点没有任何实际影响.让我解释:
选择UILabel并将原点更改为如上图所示位于右上角,将帧原点放在该点(280,11).但是,在代码中,当您实际询问帧的原点时,它被赋予(211,11),它对应于帧的左上角.因此,在界面构建器中更改框架原点似乎绝对没有任何作用!这里发生了什么?!
我有一个帮助程序类,它分发UIManagedDocument的共享实例.这个想法是用户为磁盘上的特定文件请求UIManagedDocument共享实例.在这种情况下,它是一个核心数据存储.如果用户请求位于不同路径的核心数据存储,我想为该文件分发UIManagedDocument实例.
我的问题是:创建UIManagedDocument的新实例并在文件更改时将其分配给静态变量是否可以?例如:
+ (UIManagedDocument *)sharedManagedDocumentForFile:(NSString *)fileName
{
static UIManagedDocument *sharedDocument = nil;
NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
url = [url URLByAppendingPathComponent:fileName];
// url is "<Documents Directory>/<vacationName>"
// Create the shared instance lazily upon the first request.
if (sharedDocument == nil) {
sharedDocument = [[UIManagedDocument alloc] initWithFileURL:url];
}
if (sharedDocument.fileURL != url) {
UIManagedDocument *newDocument = [[UIManagedDocument alloc] initWithFileURL:url];
sharedDocument = newDocument;
}
return sharedDocument;
}
Run Code Online (Sandbox Code Playgroud)
基本上我要做的只是分发UIManagedDocument的一个实例,所以如果核心数据存储有多个编写器,我不必经常保持更改同步.但是,由于磁盘上有多个核心数据存储,因此我不能每次都分配相同的静态变量.
有任何想法吗?我完全坚持甚至如何处理这个设计问题......任何帮助都表示赞赏.
谢谢 - 杰克
只是一个愚蠢而又快速的问题:为什么一些使用c样式字符串的函数,例如:fgets,strcpy,strcat等,当存储输出的参数列表中有变量时,返回类型为char*?即,为什么:
char *strcat ( char *dest, const char *src );
Run Code Online (Sandbox Code Playgroud)
并不是
void strcat ( char *dest, const char *src );
Run Code Online (Sandbox Code Playgroud)
甚至只是通过做返回结果
char *strcat (const char *src );
Run Code Online (Sandbox Code Playgroud)
我的意思是我可以看到如果你正在嵌套对这些函数的调用(这是危险的),这将是多么有用但我不明白为什么你需要同时拥有目标变量和返回他的结果...
我正在审查一些c编程的东西,不能相信我忘记了多少!
我将图像缓存到目录(/ Library/Caches/ImageCache /).当目录超过一定大小时,我想删除目录中最旧的文件.要完成此任务,我使用NSFileManager来检索目录内容.然后我尝试按日期对此数组进行排序并删除最旧的对象.
我的问题是当我尝试通过密钥NSURLCreationDateKey对数组进行排序时,我的程序崩溃了.
NSFileManager *defaultFM = [NSFileManager defaultManager];
NSArray *keys = [NSArray arrayWithObjects:NSURLNameKey, NSURLCreationDateKey, nil];
NSURL *cacheDirectory = [self photoCacheDirectory]; // method that returns cache URL
NSArray *cacheContents = [defaultFM contentsOfDirectoryAtURL:cacheDirectory
includingPropertiesForKeys:keys
options:NSDirectoryEnumerationSkipsSubdirectoryDescendants
error:nil];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:NSURLCreationDateKey ascending:YES];
NSArray *sortedArray = [cacheContents sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
Run Code Online (Sandbox Code Playgroud)
该程序在最后一行崩溃.有错误:
*由于未捕获的异常'NSUnknownKeyException'终止应用程序,原因:'[valueForUndefinedKey:]:此类不是密钥NSURLCreationDateKey的密钥值编码兼容.
在我的应用程序的第一次运行中,我向用户显示警报视图,以选择iCloud或本地文档存储.显示警报视图会导致以下错误:
应用程序在应用程序启动结束时应该有一个根视图控制器wait_fences:无法接收回复:10004003
为什么会这样?如何在启动时显示警报视图而不会出现此错误?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Check the user preferences for document storage options
if (![UserPreferencesHelper userDocumentStoragePreferencesHaveBeenCreated])
{
// User preferences have not been set, prompt the user to choose either iCloud or Local data storage
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Use iCloud?"
message:@"Would you like to store data in iCloud?"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"No", @"Yes", nil];
[alert show];
}
}
Run Code Online (Sandbox Code Playgroud)
**更新**
我应该提一下,我正在使用iOS 5和故事板.根视图控制器在故事板中设置.
在闰年,[NSDate date]回报2012-03-01 HH:MM:SS +TTTT.
在stackoverflow上,我经常看到通过简单调用来检索今天日期的帖子[NSDate date].问题是在闰年这不会返回正确的日期.现在我明白闰年实际上是一个日历系统的功能,因此有意义的是NSDate不能识别闰年(或者说是夏令时).但是,这有可能破坏代码中的破坏 - 例如:
假设你通过这样做来分配文件修改日期:
// assume today's date is 2012-02-29 10:00:00 +0000
NSDate *fileModificationDate = [NSDate date]; // 2012-03-01 10:00:00 +0000 is returned
Run Code Online (Sandbox Code Playgroud)
然后在将来的某个时刻进行比较以查看文件的上次修改时间:
// assume it's the next day at 9 AM, ie 2012-03-01 09:00 +0000
NSTimeInterval timeSinceLastModification = [fileModificationDate timeIntervalSinceNow];
Run Code Online (Sandbox Code Playgroud)
返回timeSinceLasModification将是积极的,表示未来的时间没有任何意义!
我的问题是:[NSDate date]用来获取当前日期实际上是不好的做法吗?我错过了一些重要的东西吗?
抱歉这个冗长的问题...
我正在尝试构建一个安全应用程序,提示用户在允许访问应用程序之前输入密码.这是在第一次启动时或应用程序恢复时完成的.
现在,我正在使用一个视图控制器,PasscodeViewController它在应用程序启动或恢复时以模态方式呈现,即在应用程序委托中:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
if (!self.passcodeViewController.view.window)
[self.window.rootViewController presentViewController:self.passcodeViewController animated:NO completion:NULL];
}
Run Code Online (Sandbox Code Playgroud)
问题是主视图控制器的视图在PasscodeViewController呈现之前暂时闪烁.这是一种安全风险,因为用户可以在被要求输入密码之前快速查看数据.
你是如何解决这个问题的?DotLockData等程序和其他安全程序如何实现这样的功能?