我有一个SEL
从当前对象获取的代码示例,
SEL callback = @selector(mymethod:parameter2);
Run Code Online (Sandbox Code Playgroud)
我有一个像这样的方法
-(void)mymethod:(id)v1 parameter2;(NSString*)v2 {
}
Run Code Online (Sandbox Code Playgroud)
现在我需要转移mymethod
到另一个对象,比如说myDelegate
.
我试过了:
SEL callback = @selector(myDelegate, mymethod:parameter2);
Run Code Online (Sandbox Code Playgroud)
但它不会编译.
你能帮我解决这个jQuery选择器吗?
$(".auctiondiv .auctiondivleftcontainer .countdown").each(function () {
var newValue = parseInt($(this).text(), 10) - 1;
$(this).text(newValue);
if (newValue == 0) {
$(this).parent().fadeOut();
chat.verify($(this).parent().parent().attr('id'));
}
});
Run Code Online (Sandbox Code Playgroud)
基本上,我想选择与.bidbutton类相同的元素,该类与每个循环中的.countdown属于同一个父级:
<div class="auctiondivleftcontainer">
<p class="countdown">0</p>
<button class="btn primary bidbutton">Lance</button>
</div>
Run Code Online (Sandbox Code Playgroud)
然后将其应用于该按钮:
$(button here).addClass("disabled");
$(button here).attr("disabled", "");
Run Code Online (Sandbox Code Playgroud) 我想声明一个SEL
类似这样的属性:
@property (nonatomic, assign) SEL mySelector;
Run Code Online (Sandbox Code Playgroud)
这是assign
"正确的吗?也许assign
可以省略?
这是我的button
对象
let loginRegisterButton:UIButton = {
let button = UIButton(type: .system)
button.backgroundColor = UIColor(r: 50 , g: 80, b: 130)
button.setTitle("Register", for: .normal)
button.translatesAutoresizingMaskIntoConstraints = false
button.setTitleColor(.white, for: .normal)
button.addTarget(self, action:#selector(handleRegister), for: .touchUpInside)
return button
}()
Run Code Online (Sandbox Code Playgroud)
这是我的功能
func handleRegister(){
FIRAuth.auth()?.createUser(withEmail: email, password: password,completion: { (user, error) in
if error != nil
{ print("Error Occured")}
else
{print("Successfully Authenticated")}
})
}
Run Code Online (Sandbox Code Playgroud)
我收到编译错误,如果addTarget删除它成功编译
我是以编程方式将UITapGestureRecognizer添加到我的一个视图中:
let gesture = UITapGestureRecognizer(target: self, action: #selector(self.handleTap(modelObj:myModelObj)))
self.imageView.addGestureRecognizer(gesture)
func handleTap(modelObj: Model) {
// Doing stuff with model object here
}
Run Code Online (Sandbox Code Playgroud)
我遇到的第一个问题是"#selector'的参数'没有引用'@Objc'方法,属性或初始值设定项.
很酷,所以我将@objc添加到handleTap签名:
@objc func handleTap(modelObj: Model) {
// Doing stuff with model object here
}
Run Code Online (Sandbox Code Playgroud)
现在我收到错误"方法无法标记为@objc,因为参数的类型无法在Objective-C中表示.
它只是建筑物地图的图像,其中一些图像指示了兴趣点的位置.当用户点击这些引脚中的一个时,我想知道他们挖掘了哪个兴趣点,并且我有一个描述这些兴趣点的模型对象.我使用这个模型对象给它在地图上的坐标图像,所以我认为将对象发送到手势处理程序是很容易的.
有没有办法将选择器存储在一个NSDictionary
,而不是存储为NSString
?
对于方法:
[NSThread detachNewThreadSelector:@selector(method:) toTarget:self withObject:(id)SELECTOR];
Run Code Online (Sandbox Code Playgroud)
如何传入@selector?我尝试将它转换为(id)以使其编译,但它在运行时崩溃.
更具体地说,我有一个像这样的方法:
+(void)method1:(SEL)selector{
[NSThread detachNewThreadSelector:@selector(method2:) toTarget:self withObject:selector];
}
Run Code Online (Sandbox Code Playgroud)
它崩溃了.如何在不崩溃的情况下传入选择器,以便新线程可以在线程准备好时调用选择器?
我想将动态生成按钮中的电影网址传递给MediaPlayer:
[button addTarget:self action:@selector(buttonPressed:) withObject:[speakers_mp4 objectAtIndex:[indexPath row]] forControlEvents:UIControlEventTouchUpInside];
Run Code Online (Sandbox Code Playgroud)
但action:@selector() withObject:
不起作用?
还有其他解决方案吗?
感谢帮助!
我有一系列的图像视图,我使用他们的标签识别.我为图像添加了一个轻击手势.
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectImage:)];
[tableGridImage addGestureRecognizer:singleTap];
tableGridImage.userInteractionEnabled = YES;
[singleTap release];
Run Code Online (Sandbox Code Playgroud)
这设法调用selectImage选择器ok,但将手势作为发送者传递.我需要将imageview作为发件人,这样我才能获得标签.
关于如何获得imageview及其标签的任何想法?
为什么这不适用于swift 3?它在运行时崩溃说:
' - [my_app_name.displayOtherAppsCtrl tap:]:无法识别的选择器发送到实例0x17eceb70'
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Register cell classes
//self.collectionView!.register(ImageCell.self, forCellWithReuseIdentifier: reuseIdentifier)
// Do any additional setup after loading the view.
let lpgr = UITapGestureRecognizer(target: self, action: Selector("tap:"))
lpgr.delegate = self
collectionView?.addGestureRecognizer(lpgr)
}
func tap(gestureReconizer: UITapGestureRecognizer) {
if gestureReconizer.state != UIGestureRecognizerState.ended {
return
}
let p = gestureReconizer.location(in: self.collectionView)
let indexPath = self.collectionView?.indexPathForItem(at: p)
if let index = indexPath { …
Run Code Online (Sandbox Code Playgroud) selector ×10
ios ×4
objective-c ×4
iphone ×2
swift ×2
action ×1
cocoa ×1
cocoa-touch ×1
gestures ×1
jquery ×1
media-player ×1
nsdictionary ×1
parameters ×1
properties ×1
swift3 ×1
uikit ×1