小编AsT*_*TeR的帖子

如何处理自定义标注视图上的点击?

我正在添加一个这样的callout视图:

func mapView(mapView: MKMapView!,
        didSelectAnnotationView view: MKAnnotationView!) {
    let calloutView = UIView(frame:
        CGRect(x: 0, y: 0, width: 300, height: 120))

    calloutView.backgroundColor = UIColor.purpleColor()
    calloutView.center = CGPointMake(CGRectGetWidth(view.bounds) / 2.0, 0.0)
    calloutView.layer.anchorPoint = CGPointMake(0.5, 1.0)
    calloutView.layer.masksToBounds = false

    calloutView.userInteractionEnabled = true
    let calloutViewTapRecognizer = UITapGestureRecognizer(target: self,
        action: "onCalloutViewTap")
    calloutView.addGestureRecognizer(calloutViewTapRecognizer)

    view.addSubview(calloutView)
}
Run Code Online (Sandbox Code Playgroud)

虽然我的onCalloutViewTap函数从未被调用过......但我很想知道为什么以及能够处理与我的标注视图交互的东西.

cocoa-touch mapkit ios swift

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

iOS应用程序在发布时崩溃但未在开发中崩溃,Swift符号未解析

我的应用程序在开发中工作得非常好,但切换到生产/ AdHoc版本它在转换到我的应用程序流程的第三个UIViewController时崩溃了.

在构建之间不应该有任何区别.我从"设备"窗口中检索了日志:

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x00000001000d49ac
Triggered by Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   MYAPP                           0x00000001000d49ac 0x100010000 + 805292
1   UIKit                           0x00000001868a8954 -[UIViewController loadViewIfRequired] + 688
2   UIKit                           0x00000001868a8664 -[UIViewController view] + 28
3   UIKit                           0x0000000186f9c1cc -[_UIFullscreenPresentationController _setPresentedViewController:] + 72
4   UIKit                           0x0000000186ba378c -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 116
5   UIKit                           0x0000000186bbeb4c -[UIViewController _presentViewController:withAnimationController:completion:] + 1968
6   UIKit                           0x0000000186bc0f64 __62-[UIViewController presentViewController:animated:completion:]_block_invoke + 116
7   UIKit                           0x0000000186995c48 -[UIViewController presentViewController:animated:completion:] + 212
8 …
Run Code Online (Sandbox Code Playgroud)

xcode ios swift

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

从Python格式解析

Python中是否有任何方法可以反转通过"%"运算符完成的格式化操作?

formated = "%d ooo%s" % (12, "ps")
#formated is now '12 ooops'
(arg1, arg2) = theFunctionImSeeking("12 ooops", "%d ooo%s")
#arg1 is 12 and arg2 is "ps"
Run Code Online (Sandbox Code Playgroud)

编辑 Regexp可以解决这个问题,但是它们更难写,我怀疑它们更慢,因为它们可以处理更复杂的结构.我真的很喜欢sscanf.

python

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

是否可以在svg标签内使用插入img:在伪CSS选择器之后?

我有一系列<circle>通过算法动态定位<svg>.我想在每个圆圈旁边添加一个图标,我正试图通过:

.node:after {
      content:url(/img/icon.png);
}
Run Code Online (Sandbox Code Playgroud)

选择器是正确的,因为我在Firebug中看到它但没有图标显示.我想做一些不可能的事吗?为什么我不在某处看到我的图标?

额外的问题:是否可以将此图标相对于圆形元素的中心定位.

html5 svg css3

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

JavaScript Map Reduce:奇怪的行为

var t = [-12, 57, 22, 12, -120, -3];

t.map(Math.abs).reduce(function(current, previousResult) {
    return Math.min(current, previousResult);
}); // returns 3

t.map(Math.abs).reduce(Math.min); // returns NaN
Run Code Online (Sandbox Code Playgroud)

我不明白为什么第二种形式不起作用.欢迎任何解释.

编辑:技术背景:Chrome和Firefox JavaScript引擎.见ES5减少http://www.ecma-international.org/ecma-262/5.1/#sec-15.4.4.21

javascript mapreduce

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

为什么Scrapy只爬一页?

我正在尝试测试Scrapy爬行网页,我不明白为什么我的抓取工具只抓取一个页面,我试图评论规则和allowed_domains没有成功.我想有一些愚蠢的东西,我错过任何帮助都会感激.

from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.spider import BaseSpider
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor

class NYSpider(CrawlSpider):
    name = "ny"
    allowed_domains = ["nytimes.com"]
    start_urls = ["http://www.nytimes.com/"]

    rules = (
        Rule(SgmlLinkExtractor(allow=('/2012', )),  callback='parse_article'),
        Rule(SgmlLinkExtractor(allow=('/page', ))),
    )

    def parse(self, response):
        print 'page '+response.url

    def parse_article(self, response):
        print 'article '+response.url
Run Code Online (Sandbox Code Playgroud)

任何对整个站点进行爬行的程序样本也会受到欢迎.

scrapy

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

如何在Python中按名称设置变量?

编辑2:因为很多人都在反对这个用例可以揭示的糟糕设计.这些问题和答案的读者在使用之前应该三思而后行

我试图在Python中用它的名字设置一个变量(不是属性):

foo = 'bar'
thefunctionimlookingfor('foo', 'baz')
print foot #should print baz
Run Code Online (Sandbox Code Playgroud)

PS:通过名称(没有eval)访问变量的函数将是一个加号!

编辑:我知道字典存在,这种用法是不鼓励的,我选择将它用于一个非常特定的目的(根据环境配置文件修改),这将让我的代码更容易阅读.

python

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

如何使用Facebook iOS SDK管理生产和开发凭证

症状

我的应用程序正在使用Facebook让用户登录.它在从XCode进行调试并通过AdHoc部署进行测试时工作正常,为了让外部测试人员提交我们的应用程序进行审核,但似乎Facebook在OAuth流程期间抱怨"App Not安装程序:此应用程序的开发人员尚未正确设置此应用程序进行Facebook登录".

假设

FacebookDisplayNameFacebookAppId存在于Custom iOS target propertiesinfo我的目标的XCode中节相匹配的Facebook应用程序的开发版本.不知何故,SDK必须检测到在审核期间应用程序不再处于开发状态并且发生错误.

如何在该目标中定义一些Custom iOS target properties具有不同releasedebug值的?

xcode ios facebook-ios-sdk

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

如何在实际项目中使用Zend Framework 2中的Zend\Db?关于外键和关系的任务

我已经完成了Zend 2的教程,感觉Zend\Db组件有点失望.实际上,它无法处理外键(作为内置).

如何为现实世界的项目(至少十个不同的表和关系)解决这个问题?

我是否应该考虑尝试或多或少地重写Zend_Db(ZF1)的findDependentRowset或findParentRow?我错了,如果我认为这是不可能的,因为它会打破PHP对象的教条,不知道用Data Mapper模式销售的外部世界.

我是否应该始终认为使用外键/关系的代码在表示实体的对象中无关?这可能最终成为一个美丽的意大利面条代码.

我应该放弃Zend\Db for Doctrine还是Propel?

zend-db zend-framework2

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

迭代Ruby哈希,意外行为

r = {}
r[0] = [1, 2]
r[2] = [1, 2, 4]
r[4] = [1, 2, 5]
r[6] = [1, 2]

count = 0
r.each do |x|
    count += x.length
end 

puts count #output is 8 expected value is 10
Run Code Online (Sandbox Code Playgroud)
  1. 为什么会这样?
  2. 如何实现预期的行为(获得长度的总和)

ruby

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