这是我以前用过的,
var barButtonItem = UIBarButtonItem(image: backImgs, style: UIBarButtonItemStyle.plain, target: self, action: Selector("menuButtonTapped:"))
Run Code Online (Sandbox Code Playgroud)
但是Swift 3有一些语法更改.提前感谢.
看看这个示例代码:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let letterButton = UIButton.buttonWithType(.Custom) as UIButton
self.view.addSubview(letterButton)
letterButton.addTarget(self, action:Selector("buttonDidTap:"), forControlEvents: .TouchUpInside)
}
func buttonDidTap(button: UIButton!) {
print(button.char)
}
}
Run Code Online (Sandbox Code Playgroud)
UIButton
只要Selector是公共的或内部的,工作的目标操作就可以了,但是如果它是私有的,它会因为无法识别的选择器发送到实例而崩溃
有什么办法可以实现吗?我不想公开或内部使用tap功能.
我试图在一段时间后调用一个方法.
我知道有一个解决方案:
[self performSelector:@selector(myMethod) withObject:nil afterDelay:delay];
Run Code Online (Sandbox Code Playgroud)
但我的问题是:我怎样才能调用一个带两个参数的方法?
例如:
- (void) MoveSomethigFrom:(id)from To:(id)to;
Run Code Online (Sandbox Code Playgroud)
我将如何使用延迟调用此方法 performSelector:withObject:afterDelay:
谢谢
通常在量角器中,您可以选择奇异元素:
element(protractor.By.css('#fdfdf'));
Run Code Online (Sandbox Code Playgroud)
偶尔你会得到这样的东西:
element(protractor.By.css('.dfdf'));
Run Code Online (Sandbox Code Playgroud)
可能有多个元素.从定位器中选择一个定位多个元素的索引的正确方法是什么,并且仍然包含量角器发送密钥的方法?
我正在使用RecyclerView
下面的代码:
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="320dp"
android:layout_height="match_parent"/>
Run Code Online (Sandbox Code Playgroud)
和我的清单项目:
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/selector_medium_high">
<com.basf.suvinil.crie.ui.common.widget.CircleView
android:id="@+id/circle"
android:layout_width="22dp"
android:layout_height="22dp"/>
<TextView
android:id="@+id/label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="57.5dp"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
详细看这部分android:background="@drawable/selector_medium_high"
它是一个普通的选择器:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/background_high" android:state_activated="true"/>
<item android:drawable="@color/background_high" android:state_pressed="true"/>
<item android:drawable="@color/background_high" android:state_checked="true"/>
<item android:drawable="@color/background_high" android:state_focused="true"/>
<item android:drawable="@color/background_medium"/>
</selector>
Run Code Online (Sandbox Code Playgroud)
但是当我运行这段代码时,触摸行时我的背景颜色没有变化....
我试图找出通过其类选择元素的第n个子元素的语法,但是我不知道该元素的确切路径.我做不到$('parent > child > grandchild > hereIam');
所以基本上我需要能够说出来
$('#thisElement').AllRelativesWithClass('.classToSelect')
Run Code Online (Sandbox Code Playgroud)
我到底该怎么做?
id parent;
SEL selector;
// lot's of code...
if ([parent respondsToSelector:selector]) {
}
else {
// This doesn't work:
NSString *errorMessage = [NSString stringWithFormat:@"%@ in class %@ doesn't exist!", selector, parent];
}
Run Code Online (Sandbox Code Playgroud)
如何将"SEL"和"id"转换为字符串?
我正在将我的项目语法切换到Swift 2.2(xCode帮助我自动完成); 但是,我不明白新的#selector()
语法.
举个例子:
timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self,
selector: #selector(MyVC.timerCalled(_:)), //new selector syntax!
userInfo: nil, repeats: true)
Run Code Online (Sandbox Code Playgroud)
这有选择器 #selector(MyVC.timerCalled(_:))
这_:
意味着什么?你能在这个选择器中添加其他变量吗?说,#MyVC.timerCalled(_:whateverVar)
.
关于这种语法的不同之处的一般信息与早期版本的Swift中基于字符串的实现相反,我们非常感激.
我有一个对象,我想列出它响应的所有选择器.感觉这应该是完全可能的,但我找不到API.
我正在尝试使用Xcode5升级我的应用程序,但在第三方库(MagicalRecord)中遇到了许多"语义问题"."修复"这个的最快方法可能是使用:
#pragma GCC diagnostic ignored "-Wundeclared-selector"
Run Code Online (Sandbox Code Playgroud)
(来自:如何摆脱'未声明的选择器'警告)
编译器指令,但我的直觉说这不是这样做的合适方式.带有上述错误的小代码示例:
+ (NSEntityDescription *) MR_entityDescriptionInContext:(NSManagedObjectContext *)context {
if ([self respondsToSelector:@selector(entityInManagedObjectContext:)])
{
NSEntityDescription *entity = [self performSelector:@selector(entityInManagedObjectContext:) withObject:context];
return entity;
}
else
{
NSString *entityName = [self MR_entityName];
return [NSEntityDescription entityForName:entityName inManagedObjectContext:context];
}
}
Run Code Online (Sandbox Code Playgroud)
其中entityInManagedObjectContext:
没有定义方法的地方.
有关如何最好地解决这些类型的错误的任何建议,提前谢谢?!