delegates

How to call delegate from string in C#?

半世苍凉 提交于 2019-12-22 16:53:47
问题 is it possible to call a delegate stored in a variable by its variable name (as a string)? i guess i'd have to use reflection mechanism, but i'm not getting anywhere example code: class Demo { public delegate int DemoDelegate(); private static int One() { return 1; } private static void CallDelegate(string name) { // somehow get the value of the variable with the name // stored in "name" and call the delegate using reflection } private static void CallDelegate(string name, DemoDelegate d) { d

iOS Design: Using the delegate pattern in a library

醉酒当歌 提交于 2019-12-22 13:59:50
问题 I have a library project that uses ASIHTTPRequest to make URL requests and parse the responses. The library will be used by a separate iPhone app project. If my iPhone controller code responds to a touch event, then calls into the library to make URL requests, how do I best perform the requests asynchronously? In the library, if I use the delegate pattern for asynchronous requests as shown in the ASIHTTPRequest sample code, how do I return data from the library back to the calling code in the

How to add app delegate back to mainwindow.xib

对着背影说爱祢 提交于 2019-12-22 13:07:09
问题 short answer: drag a Object from Object library and set its class to delegate. Details see the answer below. I accidentally removed app delegate from mainwindow.xib. I looked into everywhere but still cannot find a way to add it back. I tried to find it online and still got no result. Can anyone help me to fix it? Thank you. My project Other's project Main.m #import <UIKit/UIKit.h> int main(int argc, char *argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, nil); } } 回答1:

Creating Delegate Events

拟墨画扇 提交于 2019-12-22 11:33:19
问题 I'm trying to create a delegate event that is accessible in another form. But the main form doesn't seen to be able to see my delegate. It say delegate name is not valid at this point. modal form public partial class GameOverDialog : Window { public delegate void ExitChosenEvent(); public delegate void RestartChosenEvent(); public GameOverDialog() { InitializeComponent(); } private void closeAppButton_Click(object sender, RoutedEventArgs e) { ExitChosenEvent exitChosen = Close; exitChosen();

UISearchcontroller searchbar delegate not working

↘锁芯ラ 提交于 2019-12-22 11:24:31
问题 class PlaceSelectorViewController: UIViewController, GMSAutocompleteResultsViewControllerDelegate, UISearchBarDelegate { I have included searchbar delegate searchController?.searchBar.delegate = self and I have set the delegate. But method func searchBarCancelButtonClicked(_ searchBar: UISearchBar) { stopHighlight() } doesn't happen. Delegate has set properly and stopHighlight() is a real function 回答1: Make delegate of searchbar in viewdidload method. override func viewDidLoad() { super

Do system object delegates in ARC need to be set to nil?

痞子三分冷 提交于 2019-12-22 11:19:20
问题 An app crashes sometimes with error objc_object::release() . The Apple Developer Technical Support mentioned this: Remember that you should always do something like _tableView.delegate = nil; in your -dealloc methods, even if you are using ARC. For compatibility reasons system objects use unsafe_unretained references to implement delegation, instead of the preferred modern replacement weak . Does that mean that I have to set the delegates of system objects to nil when the view controller is

What is the difference between different ways of attaching\detaching event handlers in C#

*爱你&永不变心* 提交于 2019-12-22 10:58:23
问题 There are two parts to my question - Firstly we can attach event handlers in following two ways - myObject.MyEvent += new EventHandler(MyHandler); myObject.MyEvent += MyHandler; As per my understanding these two are equivalent. In the second case the C# compiler does the job of creating a delegate instance from the appropriate overload from the specified method group. Is this correct? Secondly, is there any difference between the two corresponding styles of detaching the handler? If yes then

C# - automatic delegate type from method

家住魔仙堡 提交于 2019-12-22 10:27:50
问题 Any way to avoid explicitly declaring MyMethodDelegate in a scenario like this? bool MyMethod(string x) { //... } BeginInvoke(new MyMethodDelegate(MyMethod), x); I know about lambdas a-la ()=>MyMethod(x) , however I want to avoid them sometimes as they break edit-and-continue. Edit : just BeginInvoke(MyMethod, x) does not work: The best overloaded method match for 'System.Windows.Forms.Control.BeginInvoke(System.Delegate, params object[])' has some invalid arguments Argument 1: cannot convert

How do you pass a generic delegate argument to a method in .NET 2.0

随声附和 提交于 2019-12-22 10:07:15
问题 I have a class with a delegate declaration as follows... Public Class MyClass Public Delegate Function Getter(Of TResult)() As TResult ''#the following code works. Public Shared Sub MyMethod(ByVal g As Getter(Of Boolean)) ''#do stuff End Sub End Class However, I do not want to explicitly type the Getter delegate in the Method call. Why can I not declare the parameter as follows... ... (ByVal g As Getter(Of TResult)) Is there a way to do it? My end goal was to be able to set a delegate for

Passing an Event and a delegate event handler into a generic Helper Method

人走茶凉 提交于 2019-12-22 10:07:08
问题 I have these throughout my code. It's a WP7 Silverlight app. UIThreadExecutor.UIThreadExec.Execute(() => buttonControl.Click += new RoutedEventHandler(this.ButtonClickHandler)); So, the above code, on the UI thread assigning buttonControl.Click event to the event handler ButtonClickHandler .. eg: public void ButtonClickHandler(object sender, System.Windows.RoutedEventArgs e) { } What I'd like is refactor the: UIThreadExecutor.UIThreadExec.Execute(() => buttonControl.Click += new