FAQ Database Discussion Community


How to use delegates to communicate data from a custom cell to a label in the parent view

ios,uitableview,swift,delegates,protocols
I have figured out how to pass data between views with delegates in other situations but this one is stumping me. In this example I am trying to send data resulting from pressing a button, up to the label using a delegate pattern but without any success. My guess is...

Convert Func to Delegate [duplicate]

c#,.net,c#-4.0,dynamic,delegates
This question already has an answer here: Cast delegate to Func in C# 7 answers I have the following delegate defined: public delegate object MyDelegate(dynamic target); And I have a Func<dynamic, object> object: Func<dynamic, object> myFunc How can I convert myFunc to MyDelegate? I have tried these instructions, none...

Events - Publish & Subscribe

c#,events,delegates
Lets say I have a class which has a static event in it. This event is subscribe by three or more different classes. [Lets say 4] Now when something noteworthy happen the event in class got raised. As 4 different classes subscribe to the event, the corresponding handler in them...

Passing information to a custom TableViewCell - Swift

uitableview,swift,delegates,datasource,tableviewcell
The problem is this: I tried many ways to pass down information to a ViewController1 from a SecondViewController. In this first ViewController1 I have a tableView, and in this tableView, each cell will receive an image and a label. What I want to do is, in the SecondViewController, I will...

Delegates vs Calling of Functions [closed]

vb.net,delegates
Can someone explain why I would do this code this way? I Have a small grasp of delegates but don't understand the advantages Can some one try and help explain what I am doing here. I am very new to classes and delegates. Just need some help. Here is my...

Swift equivalent of id?

objective-c,swift,delegates,protocols
The question is in the title. In Objective-C, if I want to have a property (like a delegate) that HAS to adhere to a certain protocol it can be defined like so: @property (weak) id<MyDelegate> delegate; How can I do this in Swift?...

C# Delegates. Casting not working for some reason

c#,casting,delegates
2 Errors appear when I try to build this code. First one: "Argument 2 : cannot convert from double to int." Second one: "The best overloaded method for CalculatePay(double, int, Calculate) has some invalid arguments. I don't understand why the casting I've applied in the BankHolidayShift and NormalShift methods isn't...

Create generic Func from reflection

c#,reflection,delegates
I've specified type in a variable: Type hiddenType. I need to create a Func<T> delegate where T is of type specified in mentioned variable and assign an method: var funcType = typeof(Func<>).MakeGenericType(hiddenType); Func<object> funcImplementation = () => GetInstance(hiddenType); var myFunc= Delegate.CreateDelegate(funcType , valueGenerator.Method); It doesn't works - because funcImplementation is...

Delegate was not declared?

ios,objective-c,delegates
I have some view controller called mainContainer , he than import some other view controller called myPills, and add it as a subview . the mainContainer also has a protocol to send delegates to the myPills class, and it looks like : //mainContainer.h @protocol mainScrollerDelegate <NSObject> -(void)function; @end @interface MainContainerView...

Can you use equals assignment when removing delegate members in a disposing method?

c#,delegates,operators,variable-assignment,dispose
I have the following code in my class public class Receiver : IReceiver { public event EventHandler Received; public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { if (disposing) { if (Received != null) { foreach (EventHandler delegateMember in Received.GetInvocationList()) { Received -= delegateMember; } }...

Need clarification on delegates in iOS [closed]

ios,objective-c,delegates
As per Apple documentation: Delegation is a simple and powerful pattern in which one object in a program acts on behalf of, or in coordination with, another object. The delegating object keeps a reference to the other object—the delegate—and at the appropriate time sends a message to it. Please clarify....

Centralize multiple event subscriptions

c#,events,delegates
Iv'e just introduced Events and Delegates at work and one of the core questions's was. "How would you centralize the event subscriptions?" Over the last 3-4 days iv'e been working on events and delegates so we can decouple and avoid dependencies. Business Layer: //Code omitted for readability Public Class CustomerRepository...

OS X Delegate set label from other window (Xcode)

objective-c,xcode,osx,delegates
I'm quite new to Mac programming (not to Objective C). I'm developing a small application, that shows some data and opens a second window on button press. In the second window is a textfield and a submit button. If the submit button is pressed, the window should close + the...

How to add a listener to the ios keyboard Backspace Button

ios,events,delegates,keyboard,listener
In my iOS app i have 4 input pins X-X-X-X and what i want is if the user taps backspace, the value of my pin box will be deleted in an order from right to left.

Subclass as delegate of superclass

ios,objective-c,inheritance,uiviewcontroller,delegates
I have class ImageViewController. It has delegate: @protocol ImageViewControllerDelegate @optional - (void)singleTapGestureRecognizer:(UITapGestureRecognizer *)gesture; - (void)imageDidLoaded; I also have class AttachmentViewController that subclass of ImageViewController. In that class I want to get event then image property in changed. So here is my code of it change: - (void)setImage:(UIImage *)image { //...

Swift delegation - when to use weak pointer on delegate

swift,delegates,weak-references
Can someone explain when and when not to use a 'weak' assignment to a delegate pointer in Swift, and why? My understanding is that if you use a protocol that is not defined as a class you cannot, nor want to, assign your delegate pointer to weak. protocol MyStructProtocol{ //whatever...

Why do generic delegates have DelegateName(T arg)? Why not DelegateName(T arg)

c#,generics,delegates
Why do generic delegates have DelegateName<T>? Why not DelegateName(T arg) The argument already specifies the type, then why the delegate name has to be also followed by <T>, is it as naming convention, or is it for developer to know that it accepts integer or what is purpose of such...

UI Slow to Update *ONLY* If Called In Response To Change Occurring in NSURLSessionUploadTask Completion Block

ios,objective-c,delegates,nsurlsession,nsurlsessionuploadtask
The app interacts with php scripts on my server. A user can create a booking, and details are written to a database. Subsequently, they can cancel that booking. Within the app, a booking is an object, responsible for gathering its own details from the server. A booking can also cancel...

EventHandler Not Needed in Event?

c#,delegates,eventhandler
I noticed this while using the Ping class. I originally followed C#'s documentation when implementing the PingCompleted callback method: pingSender.PingCompleted += new PingCompletedEventHandler(PingCompletedCallback); However, when I was adding a new method to the Timer's Elapsed event, I noticed that I wasn't passing a new TimerElapsedEventHandler. Instead, I was just passing...

How to send enum type to Invoke (delegate) Visual C++

visual-c++,enums,delegates
I've a function to modify a PictureBox, so I need to use a delegate. My function needs an int in order to do its job, and I've created an enum in order to define the values it can have. However, when I'm invoking it, there's a problem because it cannot...

RACDelegateProxy vs Common Delegate implementation

ios,delegates,reactive-cocoa
I'm studying the ReactiveCocoa(I'm not good with FRP, neither with pure functional programming) and i saw the RacDelegateProxy class that can abstract the implementation of the delegate methods with a void return value. What i didn't get well is what are the benefits of using it, when we compare with...

Understanding the event usage wrt delegates and registration methods

c#,events,delegates
I am trying to understand the delegates and events, so far I know the concepts. I have a question in mind and want to know if I am right. There is a class Car. We create a public delegate (CarHandler), then we create a private member of delegate type (ListofMethods),...

Delegate called multiple times from asynchronous WCF method

c#,wcf,delegates
In a client application, I am using an asynchronous WCF method being called from the following code: public void doActiveDx() { this.dataservice.GetActiveDxCompleted += (s,e) => { ...do something... }; this.dataservice.GetActiveDxAsync( ); } Why is the delegate called multiple times when doActiveDx() is called but once? In my case, ...do something...,...

Dynamic where expression to use in linq

c#,lambda,delegates
I want to build a dynamic where expression to use over a list of objects. var list = new List<Dummy>(); IQueryable<Dummy> queryableData = list.AsQueryable<Dummy>(); MethodCallExpression wherExpression = Expression.Call(typeof(Queryable), "Where", new Type[] { typeof(Dummy) }, queryableData.Expression, Expression.Lambda<Func<Dummy, bool>>(lambda.Body, lambda.Parameters.First())); Update: lambda.Body lambda.Body = {(((x.Title.Contains("Mihai") Or x.Description.Contains("Mihai")) Or x.Comments.Contains("Mihai")) Or...

Swift - Passing data along with segues

ios,swift,uiviewcontroller,delegates,segue
here's the problem: I'm trying to pass along some data from one ViewController to another InfoViewController. It looks like this: Running, the app, it looks like this: Beside this two view controllers, I have some other ones in this app and their Segues are working perfectly, but, when I tap...

Setting delegate for UIImagePicker returns error - swift

ios,swift,delegates,apple,uiimagepickercontroller
Having a problem in some swift code I had written for an OCR translation app. The code snippet is below: @IBAction func btnOCR(sender: AnyObject) { var languageAlert = UIAlertController(title: "For Your Information...", message: "The OCR feature currently only supports English & French.", preferredStyle: .Alert) languageAlert.addAction(UIAlertAction(title: "Okay", style: .Default, handler: {...

Why is a delegated method public when declared in a private section?

ruby-on-rails,ruby,delegates,metaprogramming
I can make attr_reader (and the related attr_writer and attr_accessor) method(s) private by putting the declaration in a private section: class Foo private attr_reader :b end Foo.new.b # => NoMethodError: private method `b' called for #<Foo:> However, Rails' delegate and the Ruby standard library's def_delegate do not work this way....

Adding protocols for dynamically created UIPickerView

ios,objective-c,delegates,protocols,uipickerview
This question relates to this SO question (please see accepted answer). I'm adding a UIPickerView to a view which has not added the UIPickerViewDelegate or UIPickerViewDataSource protocols in its interface. However, all the required methods for the UIPickerView object has been properly implemented, and the program runs fine with these...

Direct create function while defining the method

c#,events,printing,delegates
I am trying to create an anonymous method for handling the PrintPage event of a PrintDocument object. Here's what I tried: printDocument1.PrintPage += delegate { // define method } What I want to accomplish is something like this: printDocument1.PrintPage += new PrintPageEventHandler (object sender, System.Drawing.Printing.PrintPageEventArgs e) { // define method...

Understanding Func Delegate with MVC

c#,asp.net-mvc,razor,delegates
I am trying to wrap my head around Func < T, TResult> Delegate but seems like i am not clear. I know that T is a parameter & TResult is a return type. in MVC I use this Function all the time: @model Products @Html.TextBoxFor(s=>s.my_property) now how does TextBoxFor Function...

Delegate to private function as argument for method in different class

c#,delegates,function-pointers
Let's take class A with private methods f() and g(). Let class B have public method h. Is it possible to pass pointer/delegate pointing to A.g from method A.f to B.h? Consider the following code: Class B { public B() {} public h(/*take pointer/delegate*/) { //execute method from argument }...

What is the proper way to declare a delegate variable?

cocoa,delegates,xcode6,protocols
In MyModel.h, I declared a delegate variable like this: @property(weak) IBOutlet id <MyProtocol> delegate; I've also seen a delegate variable declared like this: @property(weak) IBOutlet NSObject <MyProtocol>* delegate; I'm wondering which I should use. Also, Xcode 6.2 indicates I'm doing something wrong because when I connect the delegate outlet in...

Groovy multiple Delegate annotation/Wrapper for list

list,groovy,delegates,annotations
I'm struggling how to use the @Delegate annotation in Groovy. What I'm trying to achieve is the following. I have two types of items (itemA & itemB). ItemB basically consists of a list of itemA's, so I used the @Delegate annotation. Furthermore, multiple itemA's are stored in a collection (collectionA),...

Location of event components in a multi class situation

c#,class,events,delegates
I am trying to understand how events should be properly constructed when you have more than one class. For instance if you have class that detects value and you want to update a text box in a form, where should the event components be placed. From what I read: Event...

Automatically delegating all methods of a java class

java,reflection,delegates
Say I have a class with many of public methods: public class MyClass { public void method1() {} public void method2() {} (...) public void methodN() {} } Now I would like to create a wrapper class which would delegate all the methods to wrapped instance (delegate): public class WrapperClass...

C# language doesn't need the concept of delegates? [closed]

java,c#,c++,callback,delegates
Thanks for your objectivity, especially where C# is your language of choice. Angry downvoters, I think I've asked a legitimate question here? Otherwise leave a constructive comment, please. To the question... C++ allows passing of (generic) function pointers simply, as follows: How to pass a generic function pointer as parameter...

Can't remove methods from delegate object invocation list properly

c#,delegates
As I read here and there a little, adding to or removing methods from the invocation list with or without the new keyword of a delegate object in C# is exactly the same and produces the same IL. See this one for example: What is the difference between two ways...

ContainerViewController delegate to ChildViewController

ios,objective-c,uiviewcontroller,delegates
ContainerViewController delegate the method -delegateMethod to ChildViewController. But in the following code, -delegateMethod is not called. I think it's because _childViewController has been released. How do I fix it to make run -delegateMethod? ContainerViewController.h @protocol ContainerViewDelegate <NSObject> - (void)delegateMethod; @end @interface ContainerViewController : UIViewController @property (nonatomic, assign) id<ContainerViewDelegate> delegate; @end...

How to Invoke dynamicaly an anonymus objects function property?

c#,delegates,system.reflection,anonymous-class
I am extremely new in this area so every help will be welcomed. So I have this anonymous object(not sure thats the correct name of it): var ERRORS = new { ERROR = new Func<bool>(() =>{ return true; }) , ERROR1 = new Func<bool>(() => { return true; }) ,...

Calling a Method on an Objective-C Delegate from Swift

ios,objective-c,swift,delegates,protocols
I'm writing some Swift classes that build upon functionality in our objective-c app. I have a objective-c class with a delegate that conforms to a protocol. I'm trying to call a method on that delegate from inside of a Swift class I'm simplified it down to this. FredTestProtocol.h: @protocol FredTestProtocol...

C# How to notify other classes with a single timer?

c#,timer,delegates
I am trying to make a global timer where everything that needs to be notified after certain time has passed. For instance, in a game, there would be buffs and attack cool down timers and item cool down and much more. Managing them separately is fine, but how would I...

How to edit the main form in C# from a timer?

c#,timer,delegates
I'm trying to display an error on my form and use timer to remove the error in a second. I have: const string sendingError = "currently sending a message please wait"; System.Timers.Timer timer = new System.Timers.Timer(1000); commandValues.errorList[sendingError] = sendingError; commandValues.updateErrorList(); this functions as it should by updating a label with...

How to assign textfield or any delegate in Swift Language?

swift,delegates,uitextfield
I am just new born developer for Swift Language. I want to assign textfield delegate to view controller. I tried to assign like this class LoginViewController: UIViewController <UITextFieldDelegate> It's returning following error "Cannot specialize non-generic type 'UIViewController'"...

iOS Swift Delegate Syntax

ios,swift,delegates
I'm new to iOS and Swift. I'm having a problem understanding the syntax used in Protocol methods used in Delegates. As an example, the following two methods used in the UIPickerView: func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int { return 1 } func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { return...

Implementing Nuance Speech Recognition on Swift, cannot listen to onResult, onError… events

ios,swift,delegates,speech-recognition,header-files
I have two parts of my Speech Recon project with Nuance, the .h file of a module (ObjectiveC) and aViewController (swift). I want to set up aSpeechRecognition object in my swiftviewController, and listen to onBegin, onStop... and such methods. The only way to make it compile is to use nil...

Custom Delegate with Modal Form Sheet not working

ios,objective-c,delegates
I have gone through most of the previous related posts, but although I have followed them correctly (as far as i understood), I simply am not able to trigger the delegate method for below code. Objective: ModalView generates a string *SQL_String. Press DONE to dismiss the ModalView and trigger the...

No IBAction option for Button in UIContainerView?

ios,uitableview,swift,delegates,uicontainerview
I have a small Container View (it is a UITableViewController with some static cells) embedded within another view. I am trying to now create an IBAction for one of the buttons in the Container View, but when I select one of the cells and control drag into the custom .swift...

UISearchController & UISearchBar Subclass

ios,objective-c,delegates,uisearchbar,uisearchcontroller
Aloha. I am having trouble getting a custom subclass of UISearchController, VLSearchController, with a custom UISearch Bar to call any of its delegate methods in my UIViewController. My custom subclasses don't have any delegate methods of their own, but I thought that since they were subclasses... their delegate methods would...

C++ Java Handler equivilent

c++,callback,delegates
I'm coming from a Java/C# background and am new to C++. I am writing a library and am trying to accomplish the same functionality as a Handler does in Java. My scenario is as follows: I am building a WinRT library that a user will put into his mobile/desktop app....

delegate for all methods

c#,delegates
I want to implement a TaskQueue. I add Tasks to a Queue and when I call Run() the Tasks will be executed by a thread. class Executer { private Queue<Task> TaskQueue; private Thread thread; public Executer() { this.TaskQueue = new Queue<QueueNode>(); } public void AddTask(Task task) { this.TaskQueue.Enqueue(task); } public...

How to filter a collection of delegates based on their parameter's generic type in C#?

c#,linq,generics,delegates
I have a collection of delegates: IList<Action<ISomeInterface>> _delegates = new List<Action<ISomeInterface>>(); And a method* to add delegates to it**: public void AddDelegate<T>(Action<T> del) where T : ISomeInterface { _delegates.Add(si => del((T)si)); } Now I want to filter the delegates collection based on the concrete type the delegate is constructed with:...

Passing variable arguments to a delegate

c#,.net,c#-4.0,dynamic,delegates
I have the following delegate: public delegate object DynamicFunction(dynamic target, params object[] args); However, when I try to create it: DynamicFunction func = new DynamicFunction((t) => { //Handle t }); The compiler throws an error saying that the delegate does not take 1 argument, even though I specified the last...

Passing delegates as parameters for mediator/subscriber pattern

c#,events,delegates,params,mediator
I'm looking for the appropriate and elegant way to create Mediator/Subscriber architecture with typed callbacks. Let's suppose I have a class with 'events' i.e. delegates: public class E { public delegate void SomethingHappened (float a, int b); public delegate void ProgressFinished (int[] c); } Now I want to create a...

Are Func and Action Delegates in C# used by companies?

c#,events,delegates,action,func
I really wonder if the Func and Action delegates are used by developing companies. And do they use it for events? I know it's a strange question but I already asked it to my teacher and many other people but nobody could give me an answer.

How does QLineEdit triger QAbstractItemDelegate::commitData

qt,delegates,qlineedit,qabstractitemmodel
I am developing a Qt application using QTreeView and QAbstractItemModel. The model contains somewhat heterogenous data, which requires different controls for editing. I am implementing it by having a custom delegate, that queries model.data(Qt::EditRole) and the model would return the QWidget to be used as an editor. I like how...

Accept any type as delegate parameter

c#,unity3d,delegates
I'm trying to set up a system that allows me to easily set up delays in Unity3D (in C#), doing this without any parameters or simple parameters works just fine, but I'd like the system to be flexible enough to allow for any kind of callback. For example, in the...

Swift - label not updating in WatchKit from delegate callback

ios,swift,delegates,watchkit
I know the first question will be "are you running the code in the main thread" and the answer is yes, I am. I have an Interface Controller present a modal, and I use a delegate callback to dismiss the modal and update a text label. Here's the code: The...

Does System.Action keep a weak reference to the owner of the method?

c#,delegates
Is a weak reference used or will failing to remove all references to a System.Action keep the owner of the method it is calling alive due to this reference?

Setting the delegate from third to first viewController

ios,objective-c,delegates,protocols
I have three viewControllers. When I'm on the third view controller I want to send a message to the first one. I'm using a protocol and trying to set the delegate for this. viewControllerC.h @protocol ViewControllerCDelegate - (void)performAction; @end ... @property (nonatomic, strong) id<ViewControllerCDelegate> delegate; viewControllerA.h @interface ViewControllerA : UIViewController...

Swift: use of 'self' in method call before super.init initializes self compile error

ios,delegates,protocols
I made a custom class that handles audio recording/playback and put a Protocol in that class. I implemented the Protocol in a UIViewController class and called my setDelegate method for my AudioHelper class. I am getting a compile error that has to do with my init(). Not exactly sure how...

how to write delegate with 2 parameters

c#,delegates,syntax-error
This should be a simple question with hopefully a simple answer. I am trying to write a delegate that takes 2 parameters but the compiler does not accepts it. When I use one parameter it works, example : var addCar = new Action<string>(number => { } ); but when I...

What are protocols and delegates and how are they used in IOS? [duplicate]

ios,objective-c,delegates,protocols
This question already has an answer here: Protocols and Delegates for Dummies 4 answers I'm really confused about the concept of delegates and protocols. Are they equivalent of interfaces and adapter classes in Java? How do they work? None of the resources I've read were helpful so far. "Delegation...

Does the order of the delegate functions matter in iOS?

ios,objective-c,ios8,delegates
I've integrated the appsflyer sdk within my app. After submitting the app to the appstore there was a problem. I've contacted appsflyer support team and they told me that I should change the order of the delegate functions: in this way - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [AppsFlyerTracker sharedTracker].appsFlyerDevKey =...

Where to put Delgates in .Net Solution [closed]

c#,.net,delegates,namespace-organisation
I have a C# .Net collection of solutions which started as a proof of concept, and has grown to almost 15 different projects. I am currently in the process of rewriting the whole product family, and trying to maintain best practices to the best of my abilities, with future-proof organisation....

Programmatically switching tabBar causes IBOutlet to be nil

ios,swift,delegates,uitabbarcontroller,iboutlet
I am switching tabBar programmatically - which works fine. However, an IBOutlet mapView (google maps) becomes nil - leading to a crash... I've spent quite a few hours on this. Feels like I am missing something trivial. Looked through SO, e.g.: Switch tab bar programatically in Swift and All my...

Setting delegates (for protocols) only works in prepareForSegue?

ios,objective-c,delegates,protocols
Most of the information I found involving implementing protocols and delegates involves a step where you do this; DestinationViewController *destinationVC = [[destinationViewController alloc] init]; destinationVC.delegate = self; But after hours of frustration because I couldn't get it to work I finally stumbled across another way to allocate the destinationVC in...

swift method accept parameter if conform a protocol

ios,swift,delegates
i have a protocol named WebServiceProtocol and method like this : class func executeRequest(delegate:__SOMETHING__,url:String,postParameters:[String:String],headerParameters:[String:String]){ //Do something and call delegate } i want to have a conditional argument that check if input conform WebServiceProtocol Accept it. i'm tying to write a global class function that work with every input , maybe...

C++ Generalize delegates

.net,callback,delegates,c++-cli
i have a similiar situation: ref class Manager { delegate void answer1(String^ Message, int Avalue); delegate void answer2(Object^ Obj, double Something); answer1 ^ Callbackfor1; answer2 ^ Callbackfor2; void RegisterCallback1(answer1 ^ Address); void RegisterCallback2(answer2 ^ Address); } How can i manage that in a better solution? I had to create each...

Receive delegate method calls from multiple view controllers

ios,swift,uiviewcontroller,delegates,uisplitviewcontroller
I have an app with a SplitViewController. The MasterViewController is a UITableViewController. And the DetailViewController is a UIViewController with a MapView. I'm calling an API to get a list of events. In the tableView, I want to display the names and the addresses of the events. And in the mapView,...

How extract parameters passed by delegate parameter

c#,parameters,delegates,helpers
I try to build a helper in MVC. I try passed parameters like this: @Html.InputHandler(settings => { settings.Name = "Julio"; settings.Mask = "000-000-000"; settings.visible = false; settings.Label = true; settings.htmlAttributes = new { @class="form-control" } }) I have the following code for definition of parameters public delegate void Action<in T>(T...

Reflection - Add a Delegate to another Delegate's invocation list

c#,reflection,delegates
i am attempting to attach a Delegate to an invocation list of a different delegate. By that i am achieving a kind of Hook on existing events. I need to hook up something that runs after each event that is invoked. The following example works as long as the Delegate...

Delegate returning nil

xcode,swift,delegates,protocols
I'm trying to use a protocol / delegate in swift, and while I'm not getting any errors it seems that my delegate is not being created. Here is my code Class 1 import UIKit protocol GameViewSliding{ func slideGameView() } class GameDetailsViewController: UIViewController { var delegate:GameViewSliding? override func viewDidLoad() { super.viewDidLoad()...

Event syntax vs delegate syntax in c# application

c#,.net,events,syntax,delegates
I have searched about the use of event syntax and its importance in c# code. So I found these advantages : An event cannot be directly assigned ( we don't have the risk of someone removing all previous subscriptions, as with delegate syntax No outside users can raise the event...

Passing string back in popViewControllerAnimated

ios,uitableview,delegates,didselectrowatindexpath
I have a UIViewController(1), I press on a view in that controller and it then push's another UIViewController(2) with a full screen UITableView in it. I then press on a cell in the UITableView and want to pass back to UIViewController(1) a string in the UITableView. I have tried using...

Is there any reason to use a function with a void return over an Action in C#?

c#,function,delegates,action
Save for tradition, is there a reason why I would want to use void foo(int k) { // stuff } over Action<int> foo = new Action ((k) => { // stuff }); More generally, are there any practical advantages to defining my functions normally instead of defining them as delegates?...

How to store Action delegates with constrained generic type in a type safe collection in C#?

c#,generics,delegates
Let's say I want to store delegates in a collection like this: public void AddDelegate<T>(Action<T> action) where T : ISomething { _delegates.Add(action); } What should the type of _delegates be? Trying with IList<Action<ISomething>> _delegates; results in error message Argument type 'System.Action<T>' is not assignable to parameter type 'System.Action<ISomething>' for the...

Get the method name that was passed through a lambda expression?

.net,vb.net,reflection,delegates,pinvoke
Is it possible to retrieve via Reflection the real method name that was passed through a lambda expression? I would like to platform invoke some functions with a better error-handling, then to avoid repeating tons of Marshal.GetLastWin32Error conditionals, I thinked in create a generic method to automate that, where I...

Implementing delegate methods in separate class

ios,iphone,uiviewcontroller,delegates
I created delegate and its methods are the same to every VC that it supports. How can I use with out code duplication? My code #pragma mark - UIViewControllerTransitioningDelegate (id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source { CircularTransitionAnimator *animator = [CircularTransitionAnimator new]; animator.isPresenting = YES; self.pointForAnimationOfViewUserPhotos =...

What's the behaviour of setting multiple delegate on the same class Objective-C

objective-c,delegates
I have a ViewController that has like 5-6 delegates, when I need to initialize the delegate I use the following code: _ExampleModel.delegate = self; And I was wondering, If I need to initialize lot of delegates do I just need to call for example: _ExampleModel.delegate = self; _ExampleModel2.delegate = self;...

specify type of delegate parameter

c#,dictionary,delegates,action,trygetvalue
im trying to use TryGetValue. to Invoke a delegate inside Method i use dictionary to select one delegate and then Invoke it. the dictionary type is Dictionary<string, Action<Mesh>> _meshActions; and the action type is Action<Mesh> So here it seems i can not declare action in delegate parameter correctly. Method(null, "mesh",...

Using delegates: unexpectedly found nil while unwrapping an Optional value

ios,swift,uiscrollview,delegates,uiscrollviewdelegate
I have two ViewControllers, assume one is named MainVC and the other one is named GetCameraRollImageViewController. In the second one, there is a UIScrollView which holds a UIImageView, since I'm using segue to show the second view controller, I've to use its delegate in the MainVC: class ViewController: UIViewController, GetTextDelegate,...

Delegate with generic list signature for passing data to another form

c#,winforms,events,delegates
I'm quite new in C#, so I'm struggling with this more than two days. I hope that some one can help me out with this one. Below some simplified code from my application. I want to pass a List from Form1 to Form2 using delegate and event. How can I...

No visible @interface for 'UIViewController' declares the selector

ios,objective-c,delegates,nsurlconnection
This is day 1 of Objective C for me, so please bear with me. I am trying to allow self (referencing my LoginViewContoller class) to be accessible to my delegate method connectionDidFinishLoading, wherein I take the response and pass it to my returnResponseFromPost method in my LoginViewController.m file. Currently, in...

iOS: pass data to another class

ios,swift,delegates,block,delegation
I have my class named "Service" where inside I do a lot of GET/POST request with Alamofire, an example of request id this func requestDocuments(){ request(.POST, "http://example.com/json/docs") .responseJSON { (_, _, JSON, error) in if error == nil{ var response = JSON as NSArray println("array document: \(response)") //**** HERE I...

Typhoon injection and setting delegate

ios,swift,dependency-injection,delegates,typhoon
I'm coding in iOS with Swift. I am using plist and storyboard integration. I have an object which has a delegate. I wish to inject this object into several view controllers (not all at once) and set the delegate of this object to be the view controller which the object...

c# function which has method parameter value, or using delegate

c#,delegates,delegation
I have two button click events in my window form application. private void butProcess_1_Click(...) { /// below parameters are just sample. Process_1(int_param1, decimal_param2, datetime_param3); } private void butProcess_2_Click(...) { /// below parameters are just sample. Process_2(string_param1, guid_param2, byteArray_param3, bool_param4); } As those processes take longer time to finish executing, I...

Xcode, have delegate method auto-include classes

ios,xcode,autocomplete,delegates
In Xcode I would like to add a delegate such as UITextFieldDelegate and have methods such as textFieldShouldReturn auto added to my document In Java when I include an interface, my IDE typically forces me to auto-add some particular classes, which I tend to add code into. Is there any...

Calling delegate with multiple functions having return values

c#,delegates
I am trying to understand concept of delegates and have got a query. Suppose that we have a delegate defined with return type as int and accepting in 2 parameters of type int. Delegate declaration: public delegate int BinaryOp(int x, int y); Now, lets say we have 2 methods (add...

Closures vs Delegate pattern

ios,swift,delegates,closures
I'm working with network request classes and I'm concerned about crashes. For instance, working with closures is really easy as you pass a callback method to a function: // some network client func executeHttpRequest(#callback: (success: Bool) -> Void) { // http request callback(true) } // View Controller func reload() {...

Variable losing value in delegation pattern

objective-c,delegates
I'm trying to learn about delegation in Objective-C, and am having a minor issue with a variable losing it's data in the transfer process. I have Class1 that contains an NSMutableArray. The array gets populated, then I would like to transfer the array's values to Class2, and display it. Here...

Remove jQuery delegated event handler on specific object

javascript,jquery,delegates,event-delegation
I've attached delegated event handlers to a number of elements on the page using a single selector. As the events are triggered for individual elements, I'd like to turn off only that element's event handler based on some conditional logic. That means I won't necessarily want to disable the event...

NSUrlConnection Delegate methods are not getting called from helper class

ios,delegates,nsurlconnection,nsurlconnectiondelegate
I have to do SSL pinning so need to verify server side SSL certificate. SO I have to use NSURL delegates. I have a helper class in which I have created method which returns me login response: - (NSData *)sendSynchronousRequest:(NSString *)strNewLoginRequest returningResponse:(NSURLResponse **)response error:(NSError **)error { NSMutableURLRequest *finalRequest = nil;...

Objective-C self.delegate is null after being set

ios,objective-c,xcode,delegates
I've setup a pretty simple delegate, for a UIView. However, when I try to do: if ([self.delegate respondsToSelector:@selector(selectedPlayTrailer:)]){ [self.delegate selectedPlayTrailer:self]; } My self.delegate is null. I checked the setter that the class being set as the delegate is right by: - (void)setDelegate:(id<MyViewDelegate>)delegateClass { // Whether I overwrite this method or...

C# how cancel an executing method

c#,multithreading,delegates,thread-safety
I have a delegate method to run a heavy process in my app (I must use MS Framework 3.5): private delegate void delRunJob(string strBox, string strJob); Execution: private void run() { string strBox = "G4P"; string strJob = "Test"; delRunJob delegateRunJob = new delRunJob(runJobThread); delegateRunJob.Invoke(strBox, strJob); } In some part...

Popovers in Storyboard, how to handle the delegate

swift,delegates,storyboard
In a storyboard i have a view controller which has a segue to another viewcontroller, with the "Present As Popover" applied. If i don't add any code, this works as id expect. Issue: I need to get the delegate working so i can get data back from the popover. I...

How to use a function from the view controller in the app delegate?

ios,objective-c,delegates
I have an app that is connected to a device by Bluetooth. I want the app to send a command that indicates that the app is going to close in the app delegate method : (void)applicationWillTerminate:(UIApplication *)application {...

How does apple set the Delegates of the UIKit classes as Outlets?

delegates,uikit,protocols
I've been trying to find a way to set the delegates on my custom classes as Outlets so I can connect them via IB just like one does with an UIKit Class but I haven't been able to do this, is this even possible?

How to get tableview cell text label from 2nd viewcontroller to a label from 1st viewcontroller?

ios,uitableview,delegates,nsnotifications
I'm new iOS developer. I have 2 viewcontroller like 2 pictures below (I'll called its VC1 and VC2): VC1: And VC2 is a list of printers: Now I want every time I selected a cell in VC2 then press right bar button in top right the text label of cell...

iOS callback function from library

ios,objective-c,delegates
I am implementing an library(.a), and I want to send notification count from library to app so they can show in their UI, notification count. I want them to implement the only method like, -(void)updateCount:(int)count{ NSLog(@"count *d", count); } How can I send the count from my library continuously so...

Swift. Extending a delegate from a base class

ios,objective-c,swift,delegates,extend
I have an objc base class: @protocol BaseClassDelegate; @interface BaseClass : NSObject @property (nonatomic, weak) id <BaseClassDelegate> delegate; @end @protocol BaseClassDelegate <NSObject> -(void)baseDelegateMethod; @end I am creating a swift sub-class in which I want to extend my delegate... protocol SubClassDelegate : BaseClassDelegate { func additionalSubClassDelegateMethod(); } class SubClass: BaseClass {...