小编Dir*_*nry的帖子

UIButton事件在1%的时间内没有得到处理:我的责任链应该归咎于谁?

我的应用程序有时会忘记响应者应该处理触摸事件的内容.

我的情况:

  • 定义3个视图的XIB文件:
    • 一个视图作为文件所有者的视图
    • 以编程方式添加到视图层次结构的2个额外视图
  • 其中一个子视图(SubviewA)有一个UIButton,配置为将myAction:选择器发送FirstResponder到检测到"Touch Up Inside"事件时
  • SubviewA知道如何处理 myAction:

99%的时间,一切都很顺利.当用户点击按钮时,SubviewA负责处理该myAction:消息,一切都很好.但是,从时间到时间,用户抱怨按钮"冻结"了,我实际上转载它自己几次没有能够找到一个明确的情况下做到这一点的需求.

我到目前为止的调查是:

  • 点击按钮时没有任何反应:
    • 我的按钮检测到水龙头,因为按下时它会突出显示
    • myAction: 未在SubviewA上调用
    • 用户界面的其余部分仍保持响应

我正在谈论的代码是我正在尝试解决的一些遗留代码.有一个视图响应其子视图的事件听起来像一个奇怪的架构给我.到目前为止,我一直使用文件所有者来处理触摸事件,所以我指出响应者链是理解错误的理想选择.但我找不到原因!根据我的理解,由于按钮不知道如何处理消息并且没有附加视图控制器,它应该将其转发到其超级视图(ButtonA,它知道如何处理它)!

我的问题是:

  • 关于bug可能来自哪里的任何想法?(响应链?)
  • 关于视图是否应该自己处理其按钮行为或视图控制器应该如何处理的任何注释?

编辑:我对如何修复错误有所了解:将按钮操作直接连接到SubviewA而不是在Interface Builder中使用FirstResponder.我发布这个问题的原因是试图理解为什么响应者链不时不工作.

model-view-controller uibutton first-responder ios

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

通过cron启动时,我的Shell脚本启动Rake无法正常运行

我编写了一个Rake脚本,该脚本应该与Crontab一起自动运行.在命令行中输入时脚本运行正常,但无法在cron内正确运行.

该脚本如下所示:

#!/bin/sh

echo `date`
cd /home/mick/myapp/current
rake RAILS_ENV=production mynamespace:myaction
Run Code Online (Sandbox Code Playgroud)

crontab设置如下所示:

10 0,6,12,18 * * * /home/mick/work/launch.sh >> /home/mick/work/launch.log
Run Code Online (Sandbox Code Playgroud)

执行后,日志文件只包含日期,但没有其他内容,我在syslog中得到的错误如下所示:

Mar 18 18:10:01 CRON[21773]: (mick) CMD (/home/mick/work/launch.sh >> /home/mick/work/launch.log)
Mar 18 18:10:01 CRON[21772]: (CRON) error (grandchild #21773 failed with exit status 127)
Mar 18 18:10:01 postfix/sendmail[21776]: fatal: open /etc/postfix/main.cf: No such file or directory
Mar 18 18:10:01 CRON[21772]: (mick) MAIL (mailed 1 byte of output; but got status 0x004b, #012)
Run Code Online (Sandbox Code Playgroud)

编辑:

感谢@Holger Just的评论,我发现这个链接帮助我得到了一个有效的脚本.

这是我的脚本的更新版本

#!/usr/bin/env bash # …
Run Code Online (Sandbox Code Playgroud)

shell ubuntu cron rake ruby-on-rails

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

在CoreData中存储枚举属性并使其方便

我的一个模型对象有一个枚举属性.为了将它存储在CoreData中,我使用了一个NSNumber对象.

不过,我想以方便的方式将其作为枚举类型访问.实现这一目标的最佳做法是什么?

到目前为止,我已经使用了以下代码.

在MyObject.h中

typedef enum _ABType {
    ABTypeUnknown,
    ABTypeValue1,
    ...
    ABTypeValueN
} ABType;

@interface MyObject : NSManagedObject

@property (nonatomic, retain) NSNumber * myPersistentEnum; // Defined in my Core Data model

@property (nonatomic) ABType myConvenientEnum;
Run Code Online (Sandbox Code Playgroud)

在MyObject.m中

@dynamic myPersistentEnum;

- (BOOL)isValidEnumValue {
    if (self.myPersistentEnum) {
        int intValue = [self.type intValue];
        if (intValue >= ABTypeValue1 && intValue <= ABTypeValueN) {
            return YES;
        }        
    }

    ELog(@"Undefined enumValue %@", self.myPersistentEnum);
    return NO;
}

- (ABType)myConvenientEnum {
    if ([self isValidEnumValue]) {
        return [self.type intValue];
    } …
Run Code Online (Sandbox Code Playgroud)

enums typedef core-data nsnumber ios

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

为什么我不能使"OpenSSL with Ruby"和"Command line OpenSSL"可以互操作?

在尝试建立可互操作的加密系统时,我在轻松的"概念验证"期间遇到了一种奇怪的情况.

我在Ruby中编写了以下代码:

  • 从我的文件系统上的虚拟文本文件创建加密文件
  • 解密加密文件
  • 与原始文件进行比较并检查它们是否相同

这是代码:

require 'openssl'
require 'base64'

# Read the dummy file
data = File.read("test.txt")

# Create an encrypter
cipher = OpenSSL::Cipher::AES.new(256, :CBC)
cipher.encrypt
key = "somethingreallyreallycomplicated"
cipher.key = key

# Encrypt and save to a file
encrypted = cipher.update(data) + cipher.final
open "encrypted.txt", "w" do |io| io.write Base64.encode64(encrypted) end

# Create a decrypter
decipher = OpenSSL::Cipher::AES.new(256, :CBC)
decipher.decrypt
decipher.key = key

# Decrypt and save to a file
encrypted_data = Base64.decode64(File.read("encrypted.txt"))
plain = decipher.update(encrypted_data) + decipher.final …
Run Code Online (Sandbox Code Playgroud)

ruby encryption base64 openssl

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

信号观察者可以访问 ReactiveCocoa 信号的最后发出的值吗?

我开始使用 ReactiveCocoa,但仍然在一些基本概念上苦苦挣扎:

  1. 我的应用程序开始侦听地理位置数据(init在我的视图模型中)
  2. 我的应用程序发出带有我当前位置的信号(didFindCurrentPosition被调用)
  3. 我的视图控制器显示地图加载(viewDidLoad在我的视图控制器中)
  4. 我的视图控制器开始观察当前位置信号(仍然viewDidLoad

我的问题是:完成步骤 2 后,如果信号上没有发送其他事件,我的视图控制器不会收到通知。

我的视图控制器如何访问信号的最后一个值?(即如何在步骤 3 中访问步骤 2 中发出的值?)

感谢您的帮助。

PS:ReactiveCocoa 看起来像一个很棒的库,但我对文档的状态感到困惑。恕我直言,它不是很清楚,并且缺乏一些关于如何使用它的明确指南。

代码

视图模型:

class MyViewModel: LocationManagerDelegate {
    let locationManager: LocationManager
    let geolocationDataProperty = MutableProperty<Geolocation?>(nil)
    let geolocationData: Signal<Geolocation?, NoError>

    init() {
        geolocationData = geolocationDataProperty.signal

        // Location Management
        locationManager = LocationManager()
        locationManager.delegate = self
        locationManager.requestLocation()
    }

    // MARK: - LocationManagerDelegate

    func didFindCurrentPosition(location: CLLocation) {
        geolocationDataProperty.value = Geolocation(location: location)
    }
}
Run Code Online (Sandbox Code Playgroud)

视图控制器:

class MyViewController: UIViewController {
    let viewModel = …
Run Code Online (Sandbox Code Playgroud)

reactive-programming ios reactive-cocoa swift reactive-cocoa-5

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

Xcode 4.4将我的iOS项目变成了Mac OS X项目!我怎样才能解决这个问题?

我打开了一个iOS项目 - 使用Xcode 4.4.1 - 我没有打开2个月(即使用Xcode 4.3).首先,Xcode在显示项目导航器之后不断崩溃,说"无法关联工作树".

我试图通过删除xcuserdata文件和project.xcworkspace目录来修复它.

现在,Xcode打开而不会崩溃,但在方案视图中,它显示为Mac OS X项目,而项目和目标都正确设置为"最新iOS"基础SDK.

如何在不重新创建项目并复制所有源文件的情况下解决这个问题?

编辑:我正在使用Git与GitHub遥控器.

macos xcode build-settings ios xcode4.4

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

CocoaPods找不到来自私人仓库的豆荚

我无法使用私人cocoapods回购中的吊舱.

当我尝试使用版本0.37.1添加我的pod时,出现以下错误:

[!] Unable to find a specification for ...
Run Code Online (Sandbox Code Playgroud)

我的cocoapods配置使用2个遥控器:

$ pod repo list 

bootstragram-public-pod-repo
- Type: git (master)
- URL:  https://github.com/Bootstragram/bootstragram-public-pod-repo.git
- Path: /Users/mick/.cocoapods/repos/bootstragram-public-pod-repo

master
- Type: git (master)
- URL:  https://github.com/CocoaPods/Specs.git
- Path: /Users/mick/.cocoapods/repos/master

2 repos
Run Code Online (Sandbox Code Playgroud)

当我使用时pod install --verbose,似乎只master检查了回购,而不是私有回购:

  Preparing
    Migrating to CocoaPods 0.36

Analyzing dependencies

Updating spec repositories
Updating spec repo `master`
  ...

Inspecting targets to integrate
  Using `ARCHS` setting to build architectures of target `Pods`: (``)

...

Resolving dependencies of `Podfile` …
Run Code Online (Sandbox Code Playgroud)

ios cocoapods

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

如何将Firebase SDK用作Pod依赖项?

现在,iOS Firebase SDK是开源的,我想使用Firebase作为依赖项来构建pod。为此,我使用以下内容创建了一个新的pod模板。

我的问题是我可以从示例项目中导入FirebaseDev,但不能从开发窗格中导入。我知道在SDK开源之前这是一个问题,但我希望现在能够解决此问题,但是我需要帮助确定问题所在。有人可以帮忙吗?

.podspec

s.dependency 'FirebaseDev'
s.dependency 'FirebaseDev/Core'
s.dependency 'FirebaseDev/Auth'
s.dependency 'FirebaseDev/Database'
Run Code Online (Sandbox Code Playgroud)

Example/Podfile

pod 'FirebaseDev', :git => 'https://github.com/firebase/firebase-ios-sdk'
pod 'FirebaseDev/Core', :git => 'https://github.com/firebase/firebase-ios-sdk'
pod 'FirebaseDev/Auth', :git => 'https://github.com/firebase/firebase-ios-sdk'
pod 'FirebaseDev/Database', :git => 'https://github.com/firebase/firebase-ios-sdk'
Run Code Online (Sandbox Code Playgroud)

ios cocoapods firebase swift

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

当某些协议功能改变其签名时,我可以强制编译器失败吗?

有没有办法将某些Swift函数标记为实现某些协议函数,以便在协议的签名发生更改时,编译器可以将实现标记为错误.

例如,考虑这个例子,我有一个实例Foo协议的默认实现UIViewController,我想覆盖它作为Bar子类的自定义类UIViewController.

// V1
protocol Foo {
    func number() -> Int
}

extension Foo where Self: UIViewController {
    func number() -> Int {
        return 0
    } 
}

// Overrides the default implementation
extension Bar: Foo {
    func number() -> Int {
        return 1
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,该协议演变为:

// V2
protocol Foo {
    func numberV2() -> Int
}

extension Foo where Self: UIViewController {
    func numberV2() -> Int {
        return 0
    } 
}

// …
Run Code Online (Sandbox Code Playgroud)

xcode swift protocol-extension

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

如何使用ReactiveSwift将有错误的信号转换为NoError?(优雅)

将ReactiveSwift转换为最优雅的方式SignalProducer<A, NetworkError>Signal<A, NoError>什么?

大多数时候,我的信号生成器是网络调用的结果,所以我想将结果分成两种情况:

  • 如果值可用,请发送一个 Signal<A, NoError>
  • 如果发生错误,请发送Signal<String, NoError>带有错误的本地化描述的a

(为什么?因为我想尽可能成为MVVM)

到目前为止,我最终写了很多样板文,如下所示:

let resultsProperty = MutableProperty<SearchResults?>(nil)
let alertMessageProperty = MutableProperty<String?>(nil)

let results = resultsProperty.signal // `Signal<SearchResults?, NoError>`
let alertMessage = alertMessageProperty.signal // `Signal<String?, NoError>`

// ...

searchStrings.flatMap(.latest) { string -> SignalProducer<SearchResults, NetworkError> in
        return MyService.search(string)
}
.observe { event in 
    switch event {
        case let .value(results):
            resultsProperty.value = results

        case let .failed(error):
            alertMessageProperty.value = error

        case .completed, .interrupted:
            break
    }
}
Run Code Online (Sandbox Code Playgroud)

即:

  1. 使用 …

ios reactive-cocoa swift reactive-swift

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

是否有预处理器指令使XCode构建失败?

是否有预处理器指令使XCode构建失败?(或pragma_mark或其他)

例如,我为3种不同的环境开发了一个应用程序,包括几个要获取的Web URL.到目前为止,我不知道将用于生产环境的URL,我想在我的代码中插入一条指令,以防止预期的构建与此环境一起运行.

我的代码看起来像

#ifdef ENV1
...
#endif

#ifdef ENV2
...
#endif

#ifdef ENV3
#some_instruction_that_prevent_success_build
...
#endif
Run Code Online (Sandbox Code Playgroud)

换句话说,我想要一个充当阻塞TODO的指令.

c xcode ios c-preprocessor

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

如何重现/清理凌乱的POST参数以避免使用delayed_job的YAML序列化问题?

今天,每当我开始delayed_job工作时,这个过程都会立即死而且无声无息.

经过一些调查(并找出前景模式delayed_job),我终于发现问题是delayed_job序列化我的活动记录对象在YAML加载部分触发异常的方式:

Psych::SyntaxError: (<unknown>): mapping keys are not allowed in this context at line 7 column 14
from /Users/mick/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/psych.rb:203:in `parse'
from /Users/mick/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/psych.rb:203:in `parse_stream'
from /Users/mick/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/psych.rb:151:in `parse'
from /Users/mick/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/psych.rb:127:in `load'
from /Users/mick/.rvm/gems/ruby-1.9.3-p448/gems/safe_yaml-0.9.7/lib/safe_yaml.rb:144:in `load_with_options'
from (irb):111
from /Users/mick/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.16/lib/rails/commands/console.rb:47:in `start'
from /Users/mick/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.16/lib/rails/commands/console.rb:8:in `start'
from /Users/mick/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.16/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Run Code Online (Sandbox Code Playgroud)

delayed_job尝试时发生了什么:

YAML.load(my_job.handler)
Run Code Online (Sandbox Code Playgroud)

(其他人在我面前有同样的问题)

找到有问题的Delayed::Backend::ActiveRecord::Job实例后,puts my_job.handler会显示:

object: !ruby/ActiveRecord:MyActiveRecord
  attributes:
    id: 7648
    ... some good stuff ...
    my_field: ? …
Run Code Online (Sandbox Code Playgroud)

yaml ruby-on-rails delayed-job

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

RVM安装的mysql2 gem可以正常使用Rails ......但不能使用独立的Ruby脚本

我在Mac OS X Lion环境中使用RVM安装了Ruby和Rails.

我使用mysql2 gem(使用MAMP库而不是mysql安装)使Rails正常工作.一切都很好......

直到我尝试编写一个独立的ruby脚本(在Rails上下文中).而现在我无法让mysql2 gem工作.

从脚本内部或Ruby命令行(irb),

require "mysql2"
Run Code Online (Sandbox Code Playgroud)

指令导致以下错误:

1.9.2p290 :001 > require "mysql2"
dyld: lazy symbol binding failed: Symbol not found: _mysql_get_client_info
  Referenced from: /Users/mick/.rvm/gems/ruby-1.9.2-p290/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle
  Expected in: flat namespace

dyld: Symbol not found: _mysql_get_client_info
  Referenced from: /Users/mick/.rvm/gems/ruby-1.9.2-p290/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle
  Expected in: flat namespace
Run Code Online (Sandbox Code Playgroud)

我尝试过几种东西:

  • export DYLD_LIBRARY_PATH=/Applications/MAMP/Library/lib/mysql/:$DYLD_LIBRARY_PATH

  • 运用 sudo ln -s /Applications/MAMP/Library/lib/mysql/libmysqlclient.16.dylib /usr/lib/libmysqlclient.16.dylib

没有任何效果.我想我很快就会哭...

ruby gem rvm mysql2

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