delegates

Passing data between UIPageViewController Child views with Swift

旧时模样 提交于 2019-12-21 15:09:11
问题 I cant seem to find a specific answer to my direct dilemma. I have a UIPageViewController that programmatically loads through 6 child UIView scenes. They host various stages of an 'add' element functionality. Currently the PageViewController Class adds each child view into an array and instantiates them when required with: storyboard?.instantiateViewControllerWithIdentifier("editViewController") The natural delegate is set-up to swipe between each child scene and therefore no "

Use event and delegate in subclass

*爱你&永不变心* 提交于 2019-12-21 12:31:07
问题 Why cant i use the event declared in Base from Sub? class Program { static void Main(string[] args) { Sub sub = new Sub(); sub.log += new Base.logEvent(sub_log); sub.go(); } static void sub_log(string message, int level) { Console.Out.WriteLine(message + " " + level); } } public abstract class Base { public delegate void logEvent(String message, int level); public event logEvent log; } public class Sub : Base { public void go() { log("Test", 1); // <-- this wont compile } } 回答1: Events may

Delegate as first param to an Extension Method

懵懂的女人 提交于 2019-12-21 09:21:56
问题 Ladies and Gents, I recently tried this experiment: static class TryParseExtensions { public delegate bool TryParseMethod<T>(string s, out T maybeValue); public static T? OrNull<T>(this TryParseMethod<T> tryParser, string s) where T:struct { T result; return tryParser(s, out result) ? (T?)result : null; } } // compiler error "'int.TryParse(string, out int)' is a 'method', which is not valid in the given context" var result = int.TryParse.OrNull("1"); // int.TryParse.OrNull<int>("1"); doesnt

Delegate as first param to an Extension Method

我与影子孤独终老i 提交于 2019-12-21 09:20:14
问题 Ladies and Gents, I recently tried this experiment: static class TryParseExtensions { public delegate bool TryParseMethod<T>(string s, out T maybeValue); public static T? OrNull<T>(this TryParseMethod<T> tryParser, string s) where T:struct { T result; return tryParser(s, out result) ? (T?)result : null; } } // compiler error "'int.TryParse(string, out int)' is a 'method', which is not valid in the given context" var result = int.TryParse.OrNull("1"); // int.TryParse.OrNull<int>("1"); doesnt

Unexpected effect of implicit cast on delegate type inference

爱⌒轻易说出口 提交于 2019-12-21 09:16:19
问题 I have a simple Money type with an implicit cast from decimal : struct Money { decimal innerValue; public static implicit operator Money(decimal value) { return new Money { innerValue = value }; } public static explicit operator decimal(Money value) { return value.innerValue; } public static Money Parse(string s) { return decimal.Parse(s); } } And I defined a Sum() overload to operate on those values: static class MoneyExtensions { public static Money Sum<TSource>(this IEnumerable<TSource>

Could the CLR support a “function pointer” value type?

℡╲_俬逩灬. 提交于 2019-12-21 07:56:18
问题 A few days ago I asked why delegates are reference types, based on my misguided notion that all you need for a delegate are two references: one to an object, and one to a function. What I completely overlooked (not because I wasn't aware, simply because I forgot) is that in .NET, delegates are at least partially in place to support events as a built-in implementation of the Observer pattern, which means that every delegate supports multiple subscribers by way of an invocation list . This got

Cocoa - How to connect view's delegate to file's owner in storyboard mode?

自作多情 提交于 2019-12-21 07:19:16
问题 When I use an .xib, I connect a view's delegate to the File's Owner via interface builder, then go into the view controller's .h file and set it as the delegate to complete the connection via . However in storyboard mode, there is no file's owner object. I am using an engine called NinevehGL, which simplifies the process of rendering models with openGL. This engine requires that I create a view, set it's class to NGLView, connect it's delegate to the file's owner object, and add to the header

Objective-C @protocol equivalent in C++

百般思念 提交于 2019-12-21 05:12:16
问题 Class A has an instance of class B as a member. Sometimes the instance of class B wants to talk to class A. In Objective-C I can do: // A.h @interface A : NSObject <BDelegate> @property (nonatomic, retain) B *b; @end // A.m - (void) classBsays { } // B.h @protocol BDelegate - (void) classBsays; @end @interface B : NSObject @property (nonatomic, assign) id<BDelegate> delegate; @end // B.m @implementation B - (void) f { [delegate classBsays]; } @end I've done something similar in C++ using a

How is Progress<T> different from Action<T> ? (C#)

心已入冬 提交于 2019-12-21 05:08:12
问题 I've been using Progress<T> and wondered if it can be replaced by Action<T> . In the code below, using each of them for reporting progress, i.e. ReportWithProgress() or ReportWithAction() , didn't make any noticeable difference to me. How progressBar1 increased, how the strings were written on the output window, they seemed the same. // WinForm application with progressBar1 private void HeavyIO() { Thread.Sleep(20); // assume heavy IO } private async Task ReportWithProgress() { IProgress<int>

asp.net vb user control raising an event on the calling page

旧街凉风 提交于 2019-12-21 04:43:10
问题 i'm trying to learn about user controls. I created a user control that has a textbox and a button. What i'd like to be able to do is when i click the button in the user control, populate a label in the aspx page. I understand that i could just have a button on the page that uses some properties on the user control to get that information.. but i'd like to know how to do it with the button the user control.. the reason for this is the button is just an example.. a learning tool. if i can get