selector

how to call a method of multiple arguments with delay

 ̄綄美尐妖づ 提交于 2019-11-28 17:12:26
I'm trying to call a method after some delay. I know there is a solution for that: [self performSelector:@selector(myMethod) withObject:nil afterDelay:delay]; I saw this question and Documentation But my question is: How can I call a method that takes two parameters?? for instance: - (void) MoveSomethigFrom:(id)from To:(id)to; How would I call this method with delay, using performSelector:withObject:afterDelay: Thanks Martin Ullrich use dispatch_after: double delayInSeconds = 2.0; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); dispatch_after(popTime,

How to get rid of the 'undeclared selector' warning

夙愿已清 提交于 2019-11-28 15:14:01
I want to use a selector on an NSObject instance without the need for an implemented protocol. For example, there's a category method that should set an error property if the NSObject instance it's called on supports it. This is the code, and the code works as intended: if ([self respondsToSelector:@selector(setError:)]) { [self performSelector:@selector(setError:) withObject:[NSError errorWithDomain:@"SomeDomain" code:1 userInfo:nil]]; } However, the compiler doesn't see any method around with the setError: signature, so it gives me a warning, for each line that contains the @selector

UIButton causing unrecognized selector sent to instance

半世苍凉 提交于 2019-11-28 14:50:28
I'm trying to create multiple buttons with a for loop, but I'm having problems using the (sender:) function. I have the following code func setUpButtons(){ for i in 1...3 { let btn: UIButton = UIButton(frame: CGRect(x: 100, y: 100, width: 75, height: 100)) btn.center = CGPoint(x: 20 + 100.0 * CGFloat(i), y: 200) btn.backgroundColor = UIColor.green btn.setTitle("Click Me", for: UIControlState.normal) btn.addTarget(self, action: Selector(("buttonAction:")), for: UIControlEvents.touchUpInside) btn.tag = i self.view.addSubview(btn) } } func buttonAction(sender: UIButton!) { let btnsendtag:

How to pass in parameters into @objc function

孤者浪人 提交于 2019-11-28 14:47:16
I have a cell in a tableView, with a button I want to add an action to. The button will be an email address. When the button is pressed, I want to trigger a delegate that will have another ViewController open up an email. However, I need to be able to pass in the email as a parameter and Swift doesn't seem to let me do that. Relevant code is below: func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let row = self.sections[indexPath.section].rows[indexPath.row] switch row { case .Email: cell.infoLabel.setTitle(cellInfo.email, for: .normal) cell

Pass extra argument for UItapgestureRecognizer with selector

女生的网名这么多〃 提交于 2019-11-28 14:10:49
I have two labels, Label1 and Label2. I want to make a single function that prints out which label is tapped by creating UITTapRecognizer for both labels calling the same function with selector that passes an argument. Below is the long way of doing it which is messy but works. If I know how to pass an argument (Int) into the selector, it would be alot cleaner. let topCommentLbl1Tap = UITapGestureRecognizer(target: self, action: #selector(DiscoverCell().doubleTapTopComment1)) topCommentLbl1Tap.numberOfTapsRequired = 2 topCommentLbl1.userInteractionEnabled = true topCommentLbl1

How to pass variable to new method I call when using @selector(methodname)

末鹿安然 提交于 2019-11-28 12:45:47
问题 Ok very quick question. I am adding annotations to my iOS using MKMapAnnotation. I create a int and an annotation with a disclosure button Which calls the method loadPano like so: int integervariable; [disclosureButton addTarget:self action:@selector(loadPano) forControlEvents:UIControlEventTouchUpInside]; Now say I want to access the integer variable in the method load pano how would I do this, I am struggling to understand how I would pass the variable to the new method when it is called

NotificationCenter registered selector is not called

♀尐吖头ヾ 提交于 2019-11-28 12:38:39
问题 I currently have this code below to see if the day has elapsed, but it doesn't seem to be working. Have I coded this correctly? NotificationCenter.default.addObserver(self, selector:"calendarDayDidChange:", name:NSNotification.Name.NSCalendarDayChanged, object:nil) func calendarDayDidChange(notification : NSNotification) { // code to respond to notification } 回答1: I think the way you registered observer is not correct. Please try the below and check. NotificationCenter.default.addObserver

'Unrecognized selector sent to instance'

别等时光非礼了梦想. 提交于 2019-11-28 11:47:10
问题 I am receiving the following Error [UIViewController setThisViewData:]: unrecognized selector sent to instance 0x71800b0 2012-10-24 16:06:05.071 Movie Rental[5468:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController setThisViewData:]: unrecognized selector sent to instance 0x71800b0' at the following lines of " basicInfoViewController.m ": contactInfoViewController *destViewController = segue.destinationViewController; destViewController

UIBarButtonItem selector not working

喜欢而已 提交于 2019-11-28 11:40:42
问题 I have a MainViewController embed in a Navigation Controller, as shown below: And in MainViewController.swift, I added two UIBarButtonItem(left and right) programmatically: class MainViewController: UIViewController { let rightButton = UIBarButtonItem(title: "Right", style: .plain, target: self, action: #selector(onRightClick)) let leftButton = UIBarButtonItem(title: "Left", style: .plain, target: self, action: #selector(onLeftClick)) override func viewDidLoad() { super.viewDidLoad()

javascript getElementsByClassName() always returns none?

僤鯓⒐⒋嵵緔 提交于 2019-11-28 11:23:05
hey guys, i wanna create the simplest bookmarklet for my browser. javascript:document.getElementsByClassName('source').style.visibility='visible'; I have multiple div.source in my body. By default they are set to .source { display:none; } with css. My console tells me: Uncaught TypeError: Cannot set property 'display' of undefined When I click the bookmarklet all .source divs should be visible. What am I doing wrong here? You might need to loop through the results, like this: var divs = document.getElementsByClassName('source'); for(var i=0; i<divs.length; i++) { divs[i].style.display='block'