selector

How to pass in parameters into @objc function

若如初见. 提交于 2019-11-27 08:49:06
问题 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

Passing arguments to @selector method

妖精的绣舞 提交于 2019-11-27 07:33:12
问题 I have added a UIButton in a table view. Now when I click a particular button, I need to get the details of the object corresponding to that row. [button addTarget:self action:@selector(invite:contactmail:) forControlEvents:UIControlEventTouchUpInside]; I have used this method for the button; how can I pass arguments to this selector method? Or is there any other way to pass arguments to this method when this button is clicked? 回答1: methods you add as actions to a UIControl can have 3

How to get all HTML attributes which start with something (the attribute names, *not* their values!)

时光毁灭记忆、已成空白 提交于 2019-11-27 06:56:57
问题 I would like to get all the elements/nodes in an HTML page which contain attributes that start with something (again, the attribute names start with something, not their values!). For example, TinyMCE has a tendency of adding custom attributes to the elements it saves, like "mce_style" , "mce_href" , "mce_bogus" , etc. I would like to have something like the CSS3 selector for attribute values, [attr^="mce_"] , but not for the values, the attribute names . Of course, I can iterate through all

Why must the last part of an Objective-C method name take an argument (when there is more than one part)?

心不动则不痛 提交于 2019-11-27 06:00:30
In Objective-C, you can't declare method names where the last component doesn't take an argument. For example, the following is illegal. -(void)take:(id)theMoney andRun; -(void)take:(id)yourMedicine andDontComplain; Why was Objective-C designed this way? Was it just an artifact of Smalltalk that no one saw a need to be rid of? This limitation makes sense in Smalltalk, since Smalltalk doesn't have delimiters around message invocation, so the final component would be interpreted as a unary message to the last argument. For example, BillyAndBobby take:'$100' andRun would be parsed as

What's the difference between a method and a selector?

时间秒杀一切 提交于 2019-11-27 05:51:36
What the difference between a method, a selector and a message in Objective-C? This is a great question. Selector - a Selector is the name of a method. You're very familiar with these selectors: alloc , init , release , dictionaryWithObjectsAndKeys: , setObject:forKey: , etc. Note that the colon is part of the selector; it's how we identify that this method requires parameters. Also (though it's extremely rare), you can have selectors like this: doFoo::: . This is a method that takes three parameters, and you'd invoke it like [someObject doFoo:arg1 :arg2 :arg3] . There's no requirement that

Swift access control with target selectors

拈花ヽ惹草 提交于 2019-11-27 05:24:21
问题 Have a look at this example code: 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) } } The target action for the UIButton works fine as long as Selector is public or internal , but if it's private ,

How to apply shape and selector simultaneously for Button?

杀马特。学长 韩版系。学妹 提交于 2019-11-27 05:09:45
问题 I have applied a shape for a button like: <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <gradient android:startColor="#DD000000" android:endColor="#DD2d2d2d" android:angle="90"></gradient> <corners android:radius="15dip"></corners> </shape> Now I want to use a selector like: <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/active" android:state_pressed=

Mango search in Arrays

自闭症网瘾萝莉.ら 提交于 2019-11-27 04:43:34
问题 My document has a structure like this: { "Calibration": { "Presettings": { "Date": [ { "Value": "2016-09-02 10:11", "Type": "generated" }, { "Value": "2016-09-05", "Type": "schedule", "Duration": "5" } ] } } } How must I define the selector part of a query object to get all documents with dates (Value) less or equal to a given date and with Type=='generated' ? 回答1: First, you need to create your index. I suggest that you create an index on the Calibration.Presettings.Date field . You can use

Selector in swift3

五迷三道 提交于 2019-11-27 03:55:19
Why doesn't this work in swift 3 ? It crashes at runtime saying: '-[my_app_name.displayOtherAppsCtrl tap:]: unrecognized selector sent to instance 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

How to use addTarget method in swift 3

心不动则不痛 提交于 2019-11-27 03:42:46
here is my button object 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 }() and here is my function func handleRegister(){ FIRAuth.auth()?.createUser(withEmail: email, password: password,completion: { (user, error) in if error != nil { print("Error Occured")} else {print(