小编Rob*_*Rob的帖子

NSOperationQueue无法在IOS5中运行

我有一个项目,使用后台下载图像NSOperationQueue.它一直在使用IOS 4.3的设备上工作.但是,如果我使用基本sdk 4.3或5构建应用程序并使用IOS5在设备上运行应用程序,则应用程序崩溃.启动应用程序时,它会将NSOperation对象添加到队列中以下载图像.如果在我之间按下后退按钮,我取消它NSOperation并且它崩溃并在控制台上显示以下跟踪:

#0  0x004727b7 in ____NSOQSchedule_block_invoke_0 ()
#1  0x026a5618 in _dispatch_call_block_and_release ()
#2  0x026a7a10 in _dispatch_worker_thread2 ()
#3  0x974bb781 in _pthread_wqthread ()
#4  0x974bb5c6 in start_wqthread ()

并打印"ResourceLoadOperation isFinished = YES,而不是由它所在的队列启动"如果我评论取消方法调用,应用程序不会崩溃.NSOperationIOS5 的更改是否有任何更新?

nsoperationqueue

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

GCD与NSURLConnection

GCD用来HTTP异步发送请求.这是不起作用的代码:

dispatch_async(connectionQueue, ^{
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

        [request setURL:[NSURL URLWithString:[NSString stringWithFormat:someURL]]];


        NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
        [connection start];//Not working
    }); 
Run Code Online (Sandbox Code Playgroud)

上面的代码根本不起作用.我没有在NSURLConnectionDelegate的方法中收到任何回调.

但是,当我尝试以下代码时,一切正常,我得到了适当的回调

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

[request setURL:[NSURL URLWithString:[NSString stringWithFormat:someURL]]];

NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

dispatch_async(connectionQueue, ^{

    [connection start]; // working fine. But WHY ????
});
Run Code Online (Sandbox Code Playgroud)

有人可以解释一下块/ GCD的奇怪行为吗?

iphone grand-central-dispatch ios objective-c-blocks

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

Autolayout - 平均分配6个视图

我想在一个视图中放置6个对象(按钮).但是,他们应该遵循一些限制:

在此输入图像描述

  • 两个顶部按钮应与superview(A)具有相同的垂直距离
  • 两个底部 - 相同(C)
  • 中间的两个中心应该在superview的中心线上
  • 所有按钮(E)之间的垂直距离应相同
  • 最后但并非最不重要 - 按钮应为方形(因此宽度和高度应相同)
  • A = C
  • B = D

是否有可能只在IB中产生这种效果,还是应该使用一些额外的代码来约束?

xcode interface-builder autolayout

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

没有使用dispatch_async调用并重复NSTimer的方法

我正在开发一个应用程序,我想在单独的队列中使用调用方法dispatch_async.我希望在一定的时间间隔后重复调用该方法.但是方法没有被调用.

我不知道什么是错的.这是我的代码:

dispatch_async( NotificationQueue, ^{

        NSLog(@"inside queue");
        timer = [NSTimer scheduledTimerWithTimeInterval: 20.0
                                                 target: self
                                               selector: @selector(gettingNotification)
                                               userInfo: nil
                                                repeats: YES];

        dispatch_async( dispatch_get_main_queue(), ^{
            // Add code here to update the UI/send notifications based on the
            // results of the background processing

        });
    });

-(void)gettingNotification {
    NSLog(@"calling method ");
}
Run Code Online (Sandbox Code Playgroud)

iphone nstimer grand-central-dispatch ios

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

如何在 XCTest 中使用来自另一个目标的类进行测试

我使用 Xcode 6.1 创建一个新项目,它带有一个 Tests 目标。我正在尝试使用在同一项目中的另一个演示目标中定义的类进行测试。但是我如何实现这一点(除了将类的目标成员资格设置为演示和测试目标)?

xcode unit-testing ios xctest

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

使用UIBezierPath获取"无效上下文"错误

我试图让这个绘制一条平移手势发生的线.问题是当我尝试使用此代码时

var firstPoint: CGPoint!

var path: UIBezierPath!

@IBAction func panned(gesture: UIPanGestureRecognizer) {
    switch gesture.state {
    case .Began: firstPoint = gesture.locationOfTouch(0, inView: view)
    case .Ended: gesture.cancelsTouchesInView = true
    case .Changed:
        path.moveToPoint(firstPoint)
        path.addLineToPoint(gesture.translationInView(view))
        path.stroke()
    default: break
    }
}
Run Code Online (Sandbox Code Playgroud)

...我得到了多个错误,我不太清楚该怎么做.

Apr 2 17:40:03 MacBook-Pro.local Paint[6729] <Error>: CGContextSaveGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is …
Run Code Online (Sandbox Code Playgroud)

uibezierpath swift

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

iOS - int(unsigned int)最大值是2147483647,unsigned int不起作用?

32位整数的最大值是:2 ^ 31-1 = 2147483647.但只有负数和正数.因为这个数字的一​​半是负数.所以真正的最大值是2 ^ 32-1 = 4294967295.但在这种情况下我们只使用正数.

好的,正常的int是负数和正数.我想只使用正数,因为我希望最大值为:4294967295.我将使用"unsigned int"而不是"int"

但这不行!最大值仍为2147483647.

这是一个简单的随机数生成器的代码:

-(Action for my button) {

unsigned int minNumber;

unsigned int maxNumber;

unsigned int ranNumber;

minNumber=[self.textFieldFrom.text intValue]; //getting numbers from my textfields
maxNumber=[self.textFieldTo.text intValue]; //Should i use unsigned intValue?

ranNumber=rand()%(maxNumber-minNumber+1)+minNumber;

NSString *str = [NSString stringWithFormat:@"%d", ranNumber];

self.label.text = str;

}
Run Code Online (Sandbox Code Playgroud)

这将查看:2147483647作为最大值.

怎么了?当我从textFields获取数字时,我应该使用unsigned intValue吗?

乔纳森


在这里你可以读到这个数字.:http://en.wikipedia.org/wiki/2147483647

int unsigned integer ios

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

完成处理程序在两次调用相同方法时导致EXC_BAD_ACCESS

我正在使用本教程研究一些IAP .

首先我用这个获取产品:

-(void)fetchAvailableProductsFirstLoad:(BOOL)firstTimeLoading {
    [[IAPHelper sharedInstance] requestProductsWithCompletionHandler:^(BOOL success, NSArray *products) { ...
Run Code Online (Sandbox Code Playgroud)

帮助程序运行以下内容:

- (void)requestProductsWithCompletionHandler:(RequestProductsCompletionHandler)completionHandler {

    @synchronized(self) {
        // 1
        _completionHandler = [completionHandler copy];

        // 2
        _productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:_productIdentifiers];
        _productsRequest.delegate = self;
        [_productsRequest start];
    }
}
Run Code Online (Sandbox Code Playgroud)

当产品退回或失败时,会调用以下内容:

#pragma mark - SKProductsRequestDelegate

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {

    NSLog(@"Loaded list of products...");
    _productsRequest = nil;

    NSArray * skProducts = response.products;
    for (SKProduct * skProduct in skProducts) {
        NSLog(@"Found product: %@ %@ %0.2f",
              skProduct.productIdentifier,
              skProduct.localizedTitle,
              skProduct.price.floatValue);
    } …
Run Code Online (Sandbox Code Playgroud)

exc-bad-access storekit in-app-purchase ios skproduct

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

如何解决EKEventStore上requestAccess(to:completion :)中的无限循环?

我正在打开,EKAuthorizationStatus但即使在requestAuthorisation(to:commit:)调用并返回true并且没有错误,switch语句仍然匹配.notDetermined大小写并且其中的递归产生无限循环.它让我疯了!

我试图找出requestAuthorisation(to:commit:)实际上是如何工作的,因为我觉得这个问题都是关于并发性的东西,但我找不到任何东西,所以我无法真正理解这种情况.

因为我的代码中的递归肯定是这个无限循环的一部分,所以我尝试了一种没有递归的方法.但是,由于EKAuthorizationStatus可能会在我的应用程序调用事件存储库之间发生变化,因此我希望先检查它,然后再对所有状态做出相应的响应.因此,我必须调用我的方法来切换授权状态,一个用于请求它并处理我班级中的任何错误,我不希望出于可读性,安全性和理智的原因.

private func confirmAuthorization(for entityType: EKEntityType) throws {
    switch EKEventStore.authorizationStatus(for: entityType) {
    case EKAuthorizationStatus.notDetermined:
        // Request authorisation for the entity type.
        requestAuthorisation(for: entityType)

        // Switch again.
        try confirmAuthorization(for: entityType)

    case EKAuthorizationStatus.denied:
        print("Access to the event store was denied.")
        throw EventHelperError.authorisationDenied

    case EKAuthorizationStatus.restricted:
        print("Access to the event store was restricted.")
        throw EventHelperError.authorisationRestricted

    case EKAuthorizationStatus.authorized:
        print("Acces to the event store granted.")
    }
}

private func requestAuthorisation(for entityType: EKEntityType) {
    store.requestAccess(to: …
Run Code Online (Sandbox Code Playgroud)

recursion infinite-loop eventkit ekeventstore swift

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

什么相当于 iOS UIImageView 的 Android ImageView 的中心裁剪比例类型?

我想问一下如何缩放图像以填充UIImageView但仍保持其纵横比,就像centerCropAndroid的缩放类型ImageView一样。

uiimageview ios swift

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