小编Ste*_*veB的帖子

名为com.apple.nsurlstorage-cache的服务连接无效

我正在为iOS8创建一个自定义键盘,我很难搞清楚NSURLConnection的一些问题.

我正在使用sendAsynchronousRequest:方法,如下所示:

[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        NSLog(@"recieved asynchronous response");

        if (!connectionError) {
            [self connection:nil didReceiveData:data];
            [self connectionDidFinishLoading:nil];
        }
        else{
            NSLog(@"connection failed - %@", connectionError);
        }
    }];
Run Code Online (Sandbox Code Playgroud)

这一切似乎在一段时间(1-2天)内正常工作,我可以正确地接收数据.在这段时间之后,我开始看到以下错误消息:

 ***cachedResponseForRequest:key:handler failed: 
Run Code Online (Sandbox Code Playgroud)

Error Domain = NSCocoaErrorDomain Code = 4099"操作无法完成.(Cocoa error 4099.)"(与名为com.apple.nsurlstorage-cache的服务的连接无效.)UserInfo = 0x17579030 {NSDebugDescription =服务连接命名为com.apple.nsurlstorage-cache失效.}; {NSDebugDescription ="名为com.apple.nsurlstorage-cache的服务连接无效.";

我似乎能够再次正常工作的唯一方法是重置手机上的内容和设置.如果有人能指出我为什么会发生这种情况的正确方向,我将非常感激.提前致谢.

cocoa objective-c nsurlconnection ios ios8

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

具有自定义视图的NSMenuItem不会接收鼠标事件

我正在使用菜单栏应用程序,我正在使用NSMenuItem's view属性设置自定义视图.

视图显示正常,但我无法接收具有打开子菜单的菜单项的任何类型的鼠标单击事件.

在此屏幕截图中,我为每个项目添加了一个按钮.3个最右边的按钮功能正常,但父菜单中的按钮根本不会收到任何点击事件.

截图

我尝试了很多东西,包括:

  • 尝试使用mouseUpmouseDown方法捕获鼠标事件
  • NSWindow当鼠标进入该视图时,为自定义视图键设置
  • 添加全局和本地监视器 NSEvents

......但无济于事

即使没有添加按钮的方法,我也无法复制标准的默认行为NSMenuItem,因为如果它具有自定义视图target-action,NSMenuItem则不会调用它的回调.(我自己无法收到任何点击事件)

理论上这应该是可能的,因为我能够使用默认选项NSMenuItem(没有自定义视图)选择具有打开子菜单的菜单.

有人能帮忙吗?

谢谢

macos cocoa menubar nsmenu nsmenuitem

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

UIImageView无法更新

我正在为iPhone制作一款国际象棋游戏.电路板上的部件由一系列UIImageViews表示,每个UIImageViews代表电路板的正方形,并引用正确的图像以显示该正方形.选择了一个正方形,并且已经移动了,函数 - (void)updateBoard; 在ViewController中被调用:

-(void)updateBoard{

NSLog(@"updating board");

[square1 setImage:[UIImage imageNamed:[game imageForSquare:1]]];
[square2 setImage:[UIImage imageNamed:[game imageForSquare:2]]];
[square3 setImage:[UIImage imageNamed:[game imageForSquare:3]]];
[square4 setImage:[UIImage imageNamed:[game imageForSquare:4]]];
[square5 setImage:[UIImage imageNamed:[game imageForSquare:5]]];
[square6 setImage:[UIImage imageNamed:[game imageForSquare:6]]];
[square7 setImage:[UIImage imageNamed:[game imageForSquare:7]]];
[square8 setImage:[UIImage imageNamed:[game imageForSquare:8]]];
[square9 setImage:[UIImage imageNamed:[game imageForSquare:9]]];
[square10 setImage:[UIImage imageNamed:[game imageForSquare:10]]];
[square11 setImage:[UIImage imageNamed:[game imageForSquare:11]]];
[square12 setImage:[UIImage imageNamed:[game imageForSquare:12]]];
[square13 setImage:[UIImage imageNamed:[game imageForSquare:13]]];
[square14 setImage:[UIImage imageNamed:[game imageForSquare:14]]];
[square15 setImage:[UIImage imageNamed:[game imageForSquare:15]]];
[square16 setImage:[UIImage imageNamed:[game imageForSquare:16]]];
[square17 setImage:[UIImage imageNamed:[game imageForSquare:17]]];
[square18 setImage:[UIImage imageNamed:[game imageForSquare:18]]];
[square19 …
Run Code Online (Sandbox Code Playgroud)

uiviewcontroller uiimageview uiimage ios

4
推荐指数
1
解决办法
3430
查看次数

acosf()返回NaN

我有一个用Objective C编写的iPhone应用程序,我正在收集用户在屏幕上绘制的触摸点以创建路径.

我希望能够瘦这些数据.我通过检查点的角度是否超过某个阈值来实现此目的的方法之一.例如,如果我在a,b,c的线上取任意三个相邻点,如果角度ABC在180度的5度范围内,那么我可以移除点b而不会过多地影响线.

我试图通过将三角形ABC分成2个直角三角形来实现这一点.然后我使用acosf()来找到(BAC)处的角度和c处的角度(BCA).然后,我可以从180减去这两个角度,找到ABC的角度.

我的问题是acosf()经常返回NaN.当它返回一个数字时,我在计算器上检查它并且值是正确的.我已经尝试了返回NaN的值,但它们也不适用于计算器.我知道这是因为它们超出了acosf()的范围.我怎么能避免这个?

这是我正在使用的代码:

float prevToNextDist = ccpDistance(prevPoint.location, nextPoint.location);
    //work out the next point angle
    float pointToNextDistance = ccpDistance(point.location, nextPoint.location);
    float nextPointAngle = acosf((prevToNextDist/2)/pointToNextDistance);
    nextPointAngle = CC_RADIANS_TO_DEGREES(nextPointAngle);

    //work out the previous point angle
    float prevToPointDistance = ccpDistance(prevPoint.location, point.location);
    float prevPointAngle = acosf((prevToNextDist/2)/prevToPointDistance);
    prevPointAngle = CC_RADIANS_TO_DEGREES(prevPointAngle);

    //work out the point angle
    float pointAngle = 180 - nextPointAngle - prevPointAngle;
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

c trigonometry objective-c

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

NSMutable数组泄漏

我正在用cocos2d制作一个iPhone应用程序,我在使用泄漏工具标记了一个NSMutableArray时遇到了一些麻烦,我的应用程序显然正在泄漏.我已经解决了这个问题,但我真的不明白为什么它首先出现了,所以希望有人可以向我解释.

我已经将CCParticleSystemQuad子类化了,这样我就可以添加一些实例变量,包括名为'damagedObjects'的NSMutable数组:

@interface SonicBoom : CCParticleSystemQuad{

NSMutableArray *damagedObjects;
HelloWorldLayer *gameClass;
CGPoint radiusPoint;
CGPoint origin;    
}

@property(nonatomic, retain) NSMutableArray *damagedObjects;
@property(nonatomic, retain) HelloWorldLayer *gameClass;
@property CGPoint radiusPoint;
@property CGPoint origin;

@end
Run Code Online (Sandbox Code Playgroud)

这被初始化并且在主游戏类中分配了damagedObjects数组,通过设置autoRemoveOnFinish属性在完成时移除粒子系统:

-(void)createSonicBoom{

sonicBoom = [SonicBoom particleWithFile:@"SonicBoom.plist"];

sonicBoom.damagedObjects = [[NSMutableArray alloc]init];

sonicBoom.gameClass = self;

sonicBoom.autoRemoveOnFinish = YES;

//etc..........
Run Code Online (Sandbox Code Playgroud)

然后我重写了'SonicBoom'类的dealloc方法,以释放'damagedObjects'数组:

-(void)dealloc{

NSLog(@"Removing SonicBoom");

NSLog(@"damaged objects retain count = %i", damagedObjects.retainCount);

gameClass.sonicBoomActive = NO;

[damagedObjects removeAllObjects];

[damagedObjects release];
[damagedObjects release];

[super dealloc];

}
Run Code Online (Sandbox Code Playgroud)

出于某种原因,只有一个发布消息到阵列我得到了泄漏.我检查了保留计数(我从不打扰通常考虑这些),它是2,所以我现在发送两次发布消息,这似乎已经解决了问题.

这是发布它的最佳方式,有人可以解释为什么需要这样做吗?

谢谢

iphone memory-leaks objective-c nsmutablearray cocos2d-iphone

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