标签: selector

使用参数从方法名称创建选择器

我有一个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)

但它不会编译.

objective-c selector

57
推荐指数
3
解决办法
12万
查看次数

如何使用jQuery选择兄弟元素?

你能帮我解决这个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)

jquery selector

57
推荐指数
3
解决办法
9万
查看次数

Objective-c中类型为SEL的属性

我想声明一个SEL类似这样的属性:

@property (nonatomic, assign) SEL mySelector;
Run Code Online (Sandbox Code Playgroud)

这是assign"正确的吗?也许assign可以省略?

properties objective-c selector

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

如何在swift 3中使用addTarget方法

这是我的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删除它成功编译

selector ios swift

54
推荐指数
5
解决办法
9万
查看次数

在Swift中将参数传递给选择器

我是以编程方式将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中表示.

它只是建筑物地图的图像,其中一些图像指示了兴趣点的位置.当用户点击这些引脚中的一个时,我想知道他们挖掘了哪个兴趣点,并且我有一个描述这些兴趣点的模型对象.我使用这个模型对象给它在地图上的坐标图像,所以我认为将对象发送到手势处理程序是很容易的.

selector uikit ios swift

53
推荐指数
4
解决办法
7万
查看次数

将选择器存储为NSDictionary中的值

有没有办法将选择器存储在一个NSDictionary,而不是存储为NSString

cocoa cocoa-touch nsdictionary selector

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

如何将@selector作为参数传递?

对于方法:

[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)

它崩溃了.如何在不崩溃的情况下传入选择器,以便新线程可以在线程准备好时调用选择器?

iphone objective-c selector

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

在按钮操作上传递参数:@selector

我想将动态生成按钮中的电影网址传递给MediaPlayer:

[button addTarget:self action:@selector(buttonPressed:) withObject:[speakers_mp4 objectAtIndex:[indexPath row]] forControlEvents:UIControlEventTouchUpInside];
Run Code Online (Sandbox Code Playgroud)

action:@selector() withObject:不起作用?

还有其他解决方案吗?

感谢帮助!

iphone parameters action selector media-player

49
推荐指数
4
解决办法
11万
查看次数

UITapGestureRecognizer选择器,sender是手势,而不是ui对象

我有一系列的图像视图,我使用他们的标签识别.我为图像添加了一个轻击手势.

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及其标签的任何想法?

objective-c selector gestures ios

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

swift3中的选择器

为什么这不适用于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 ios swift3

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