小编val*_*u17的帖子

核心数据:错误:在核心数据更改处理期间捕获到异常

我现在已经遇到这个问题几天了,这真的很令人沮丧.我一直在审查我的代码,尝试了不同的东西并且一直有同样的问题.这种情况只有50%的时间并不总是如此.这使得它更难..

问题,

我正在将3个csv文件中的数据解析为我的核心数据,其中2个文件解析总是顺利但中间/第二个文件是崩溃总是发生的地方所以,这将是该文件的地址和此文件的managedObjectContext类.

错误信息

CoreData: error: Serious application error.  
Exception was caught during Core Data change processing.  This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification.  
-[__NSCFSet addObject:]: attempt to insert nil with userInfo (null)
2014-09-12 11:27:06.115 AppName[210:3907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFSet addObject:]: attempt to insert nil'
Run Code Online (Sandbox Code Playgroud)

因此,在我的FetchData类中,我尝试以不同的方式解决问题.

  • 首先,我更改了我的.csv文件并将N/A插入到所有空的字段/单元格中.
  • 其次,我正在检查我的FetchData类,如果它没有任何值,保存N/A.
  • 第三,在我的视图控制器中,我正在解析数据,我现在已经在我的核心数据中为这3个实体分离了三个不同的属性.

@property(非原子,强)NSManagedObjectContext*managedObjectContext;

@property(非原子,强)NSManagedObjectContext*managedObjectContextGI;

@property(非原子,强)NSManagedObjectContext*managedObjectContextVA;

它可能有点疯狂或其他什么,但我真的需要解决这个问题,尝试任何可能的解决方案或方法,这总是好的,我想.

ViewController调用函数来执行解析..

//at the beginning of my model
#define kBgQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)

-(IBAction)myLoadingTask:(id)sender{

       dispatch_async(kBgQueue, ^{ …
Run Code Online (Sandbox Code Playgroud)

csv core-data objective-c ios

23
推荐指数
2
解决办法
2万
查看次数

Autolayout约束警告"将尝试通过破坏约束来恢复"(可能的逻辑问题)

我在这个设备上运行应用程序时为iPhone 4设置了一些细节限制.在对齐和一切方面,一切看起来都很棒.

但是,我正在试图通过打破约束来试图恢复它们.

当它检测到它是iPhone 4时,此方法在我的viewDidLoad中调用

- (void) addConstraints {

    // removing automatic system constraints
    [self.view removeConstraints:self.view.constraints];
    [self.view setTranslatesAutoresizingMaskIntoConstraints:NO];


    NSDictionary *views = NSDictionaryOfVariableBindings(appBackground, myCustomer, myItemDetails, myItemQuantity, myItemPrice, myNext, myBtn); // UIImageView, UITextField, UIButton

    for (UIView *view in [views allValues]) {
        view.translatesAutoresizingMaskIntoConstraints = NO;
    }

    NSDictionary *metrics = @{@"width": @210.0, @"height": @42.0, @"verticalSpacing": @34};

    NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[appBackground]|"
                                                                   options:0
                                                                   metrics:nil
                                                                     views:views];

    constraints = [constraints arrayByAddingObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[appBackground]|"
                                                                   options:0
                                                                   metrics:nil
                                                                     views:views]];

    constraints = [constraints arrayByAddingObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(85)-[myCustomer(==height)]-(verticalSpacing)-[myItemDetails(==height)]-(verticalSpacing)-[myItemQuantity(==height)]-(verticalSpacing)-[myItemPrice(==height)]-(18)-[myNext(==35)]-(71.5)-[myBtn(==50)]-(7.5)-|"
                                                                    options:0
                                                                    metrics:metrics
                                                                      views:views]];

    constraints = [constraints arrayByAddingObjectsFromArray:[NSLayoutConstraint …
Run Code Online (Sandbox Code Playgroud)

objective-c ios autolayout nslayoutconstraint

9
推荐指数
1
解决办法
2万
查看次数

在没有NSNotificationCenter的iOS 8中为Youtube嵌入视频正确强制或允许横向模式

我有问题,当youtube播放器将全屏进入或在iOS 8中退出全屏时因为这些通知被删除UIMoviePlayerControllerDidEnterFullscreenNotification而且UIMoviePlayerControllerWillExitFullscreenNotification此版本的操作系统版本.

由于我的应用程序项目仅设置为纵向模式,因此在播放时视频不会旋转为横向模式,这在您的设备上观看视频时实际上不太友好.

通常,当视频以全屏模式进入时,用户希望以纵向模式或横向模式观看视频.

这就是我为iOS 7做的方式,它在iOS 8中运行得很完美.

首先,我将AppDelegate.m在我AppDelegate.h调用 videoIsInFullscreen 和函数的boolean属性中设置此函数,

// this in the AppDelegate.h
@property (nonatomic) BOOL videoIsInFullscreen;


// This in my AppDelegate.m to allow landscape mode when the boolean property is set to yes/true.
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
    if(self.videoIsInFullscreen == YES)
    {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    else
    {
        return UIInterfaceOrientationMaskPortrait;
    }
}
Run Code Online (Sandbox Code Playgroud)

然后在我的ViewController.m第一个,我会#import "AppDelegate.h"在这之后,我将在我的viewDidLoad方法中添加一些通知..

-(void)viewDidLoad {

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerStarted) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil]; …
Run Code Online (Sandbox Code Playgroud)

objective-c youtube-api uiwebview ios uiwebviewdelegate

5
推荐指数
1
解决办法
4165
查看次数

以编程方式设置导航栏?

我以编程方式呈现视图控制器,但是当出现视图控制器时,它缺少导航栏.有没有办法在调用时在这个新的视图控制器上以编程方式设置导航栏?

到目前为止,这是我的代码:

//LOAD CRICKET GAME
if gameGAMETYPE[index] == "Cricket" && gameGAMEPLAYERS[index] == "1" {

    println("LOAD ONE PLAYER CRICKET")
    //load OnePlayerCricket.swift
    //replace tableData with TABLEDATA

    //programatically present new view controller
    if let resultController = storyboard!.instantiateViewControllerWithIdentifier("OnePlayerCricketVC") as? OnePlayerCricket {
        presentViewController(resultController, animated: true, completion: nil)

        //programmatically present a navigation bar

         NEED HELP HERE!!!! thank you :)

}
Run Code Online (Sandbox Code Playgroud)

iphone ios swift

5
推荐指数
1
解决办法
9946
查看次数

为什么我的Realm对象没有保存存储的值?

我正在浏览寻找一个解决方案,在我的一个应用程序中实现一个小型离线数据存储,这将很容易和快速使用.无论如何,我遇到了Realm这样做.但是,我遇到的问题是,每次启动应用程序时,数据库中的内容都为空.

我做了所有的分配并调用了beginWriteTransaction方法.设置我的数据库变量值.然后,我将对象添加到领域,最后是commitWriteTransaction.

所以,我做一个NSLog来查看该值是否实际设置正确(在我的应用程序中更新之后).但是当我关闭我的应用程序或停止并在xcode iphone5模拟器中再次运行它.我尝试在viewDidLoad方法中设置数据库中的值到我的应用程序中的全局变量.我执行的NSLog来检查值是在我的数据库或全局变量,但它显示为空,也没有得到店/保存的意义.

这是代码..

@interface iReceiptDataBase : RLMObject

@property NSString* receiptNo;

@end

RLM_ARRAY_TYPE(iReceiptDataBase)

@implementation iReceiptDataBase

@end

//******** View Controller Implementation ************

- (void)viewDidLoad {

    self.realm = [RLMRealm defaultRealm]; // property type RLMRealm
    [realm beginWriteTransaction];

    self.myDataBase = [[iReceiptDataBase alloc] init]; // property type iReceiptDataBase
    receiptNumber = [myDataBase.receiptNo intValue];

    NSLog(@"In my realm database(first call) -> %@", myDataBase.receiptNo);

    NSLog(@"In my local app(first call) -> %d", receiptNumber);

}

-(void)drawPDF:(NSString*)fName {

    receiptNumber += 1; …
Run Code Online (Sandbox Code Playgroud)

objective-c realm ios

3
推荐指数
1
解决办法
8273
查看次数

我的布局键盘上的空格按钮大小不会调整大小

我正在开发一个包含键盘的打字应用程序,但我发现有点难以重新调整空间按钮的大小,使其比其他按钮更宽..这是我显示和组织我的布局的方式..

我可以调整整个按钮的大小,但它不是我想要的..整点就是调整空格键... :)

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Arrays;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class example extends JFrame 
{  
    //Individual keyboard rows  
    String firstRow[] = {"~","1","2","3","4","5","6","7","8","9","0","-","+","BackSpace"};
    String secondRow[] = {"Tab","Q","W","E","R","T","Y","U","I","O","P","[","]","\\"};
    String thirdRow[] = {"Caps","A","S","D","F","G","H","J","K","L",":","\"","Enter"};
    String fourthRow[] = {"Shift","Z","X","C","V","B","N","M",",",".","?","   ^" };
    String fifthRow[]={"               " ,"<" ,"v",">" };
    String strText = "";
    //all keys without shift key press
    String noShift="`1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./";
    //special characters …
Run Code Online (Sandbox Code Playgroud)

java keyboard swing awt jpanel

2
推荐指数
1
解决办法
947
查看次数