我有一个随机的错误困扰了我几个月,我根本无法弄清楚.我会说它在1000次中失败的次数少于1次.我必须正确配置CoreData,但我无法弄清楚或重新创建它.基本要点是我从服务器接收一些信息,然后我在后台线程中更新CoreData对象.UI不会立即需要CoreData对象.
所有这些都在DataService中执行,它引用了最初在AppDelegate中创建的NSManagedObjectContext.注意:引用[DataService sharedService]的任何内容都使用AppDelegate.NSManagedObjectContext:
@interface DataService : NSObject {}
@property (nonatomic,strong) NSManagedObjectContext* managedObjectContext;
@end
Run Code Online (Sandbox Code Playgroud)
当服务器返回数据时,将调用updateProduct方法:
@implementation DataService
+ (NSManagedObjectContext*) newObjectContext
{
NSManagedObjectContext *context = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; //step 1
AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[context setPersistentStoreCoordinator:appDelegate.persistentStoreCoordinator];
[context setMergePolicy:NSMergeByPropertyObjectTrumpMergePolicy];
[appDelegate.managedObjectContext observeContext:context];
return context;
}
+(void) saveContext:(NSManagedObjectContext*) context
{
NSError *error = nil;
if (context != nil) {
if ([context hasChanges] && ![context save:&error]) {
// Handle Error
}
}
}
+(void) updateProduct: (Product*) product
{
if(product == nil)
return;
//run in …Run Code Online (Sandbox Code Playgroud) 我正试图围绕AutoLayout工作,我认为除了UIScrollViews我理解其中的大部分内容.当我将这些视图添加到项目时,他们拒绝扩展屏幕的尺寸.它们在iPhone垂直视图中显得很好,但在旋转时,它们不会扩展.此外,当您在iPad模拟器中启动项目时,UIScrollView屏幕将不会扩展到iPad的尺寸.实际的UIScrollView扩展但它的内容不会扩展.
我按照Apple的说明(https://developer.apple.com/library/ios/technotes/tn2154/_index.html)修复了我的动态内容高度问题,但它还没有解决UIScrollView的问题内容不会扩展以匹配屏幕的宽度.我已经读过,我需要将scrollview的内部子项固定到UIView的右边缘,但这看起来有点像黑客,这似乎与上面的Apple文档相矛盾.
这就是我所拥有的:
来自viewDidLoad的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
UIView* contentView = self.contentView;
UIScrollView * scrollView = [[UIScrollView alloc] init];
[self.view addSubview:scrollView];
[scrollView addSubview:contentView];
//remove auto contraints
[scrollView setTranslatesAutoresizingMaskIntoConstraints:NO];
[contentView setTranslatesAutoresizingMaskIntoConstraints:NO];
// Set the constraints for the scroll view and the image view.
NSDictionary* viewsDictionary = NSDictionaryOfVariableBindings(scrollView, contentView);
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[scrollView]|" options:0 metrics: nil views:@{@"scrollView":scrollView}]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[scrollView]|" options:0 metrics: nil views:@{@"scrollView":scrollView}]];
[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[contentView]|" options:0 metrics: nil views:viewsDictionary]];
[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[contentView]|" …Run Code Online (Sandbox Code Playgroud) 在RestKit 0.2中,如何允许我的应用程序连接到具有无效https安全证书的服务器?从AFNetworking文档来看,我所要做的就是#define _AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_.但是,我已将该命令添加到我的pch文件,Build Settings> Preprocessor Macros和我的App Delegate.所有这些都无法连接.有任何想法吗?
我有一个使用RestKit 0.10.2的应用程序,我可以使用iOS 5.1.1在Xcode 4.4.1模拟器中构建和运行应用程序.我也可以毫无问题地运行Analyze.但是,当我尝试配置应用程序时,构建失败,找不到词法或预处理器问题RestKit/Reskit.h文件.
以下是我在目标中的标题搜索路径>调试中所拥有的内容:
$(BUILT_PRODUCTS_DIR)/../three20
$(BUILT_PRODUCTS_DIR)/../../three20
"$(BUILT_PRODUCTS_DIR)/../../Headers"
Run Code Online (Sandbox Code Playgroud)
我能错过什么?当我从0.94升级到0.10.2时,我完全从我的项目中删除了Restkit并重新导入它,因为我遇到了很多问题,试图让正常运行时解决这个完全相同的问题.有任何想法吗?
ios ×4
objective-c ×3
restkit ×2
autolayout ×1
core-data ×1
restkit-0.20 ×1
uiscrollview ×1
uiview ×1
xcode ×1