w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to call NSURLConnection delegates methods before calling UITableview delegates methods in uiviewcontroller
Simple answer is, after the completion of NSURL operation just reload the table view using reload method as follows: [yourTableView reloadData]; whenever you want to refresh the table data or calling the tableview delegate methods use reloadData method of the table view. if you over ridding the NSURLConnection delegate methods in side the same UIViewController you can refresh the table from this NSURLConnectionDelegateMethod once request is completed. - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { //Code for handling the service response here [yourTableView reloadData]; }

Categories : Iphone

How to use delegates
It is better for you, to use the select statement in your case. A delegate is not necessary. For example: you can use a delegate to call a method that is currently in use by another thread for safe coding.

Categories : Vb.Net

C# delegates from C++
I've to store the reference of the delegate to avoid that GC delete the reference of the delegate: public delegate void OnInputDownDelegate(int input); private OnInputDownDelegate mDelegate; [DllImport("mylib.dll", CallingConvention = CallingConvention.Cdecl)] internal static extern void libRegisterInput( OnInputDownDelegate f ); public void RegisterOnInput(OnButtonDownDel f) { mDelegate = f; libRegisterInput( mDelegate ); }

Categories : C#

What are delegates, how are they used?
From what you are saying, your ideas regarding delegates do not seem to be completely clear. Thus, the whole point of this answer is clarifying what delegates actually are such that you can apply this knowledge to understand the code you propose or any other delegate-related situation. Delegates are a way to treat functions as variables. That is, instead of doing Dim myString as String = "this", substituting "this" with a function. Simple code to clarify what a delegate is and how it has to be treated: Public Class Form1 Public Delegate Sub subDelegate(arg1 As String, arg2 As String) Public subDelegateVar As subDelegate Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load subDelegateVar = New subDelegate(AddressOf origSub)

Categories : Vb.Net

Use of delegates in NSOperation
Its going to call the delegate method in the same operation queue as main is running in. And NSOperation queues are serial by default. Your while loop is just spinning forever (because the operation is never cancelled) and the call to your delegate method is sitting in the queue behind it never able to run. Get rid of the while loop entirely and let the operation finish. Then when the delegate method is called, if it's cancelled discard the result by returning.

Categories : IOS

Delegates with same signature
There's no implicit conversion between those two delegates for the same reason that there's no implicit conversion between these two types: public sealed class Foo1 { public string Value { get; set; } } public sealed class Foo2 { public string Value { get; set; } } Just because two classes have the same fields doesn't mean that you should be able to treat one as if it were another. The same logic applies to delegates (which are also types, mind you). There is semantic meaning applied to the creation of that type. If someone created a Foo1 they want it to be a Foo1, not a Foo2. If they're going out of their way to use a Foo1 where a Foo2 is expected, it's a big red flag that even though the types appear similar, there is a semantic difference between these two types. If the

Categories : C#

What are delegates in ruby?
here the official explanation, but there are a lot of posts about this throughout the web. here's some better explantations of how it works with examples: http://brettu.com/rails-daily-ruby-tip-20-use-the-delegate-method-in-rails-to-reduce-code/ http://www.simonecarletti.com/blog/2009/12/inside-ruby-on-rails-delegate/ http://pivotallabs.com/rails-delegates-are-even-more-useful-than-i-knew/

Categories : Ruby On Rails

Regarding Events and Delegates in C#
An event consists of two special methods, called accessors, namely add and remove. Both take in one value parameter value of the same delegate type, and return void. For example this is an event: public event Action Exploded { add { Console.WriteLine("Hello from 'add'. Type of 'value' is '{0}'.", value); } remove { Console.WriteLine("Hello from 'remove'. Type of 'value' is '{0}'.", value); } } A "field-like" event is a compiler-generated type of event where there is a private generated backing field of the delegate type in question, and where the add accessor adds value to the invocation list of that backing field (delegate combination) whereas the remove accessor removes value from that list. This is done in a smart thread-safe way.

Categories : C#

What exactly are protocols and delegates and how are they used in IOS?
A protocol which declared with the (@protocol syntax in Objective-C) is used the declare a set of methods that a class that "adopts" (declares that it will use this protocol) will implement. This means that you can specify in your code that, "you don't care which class is used so long as it implements a particular protocol". This can be done in Objective-C as follows: id<MyProtocol> instanceOfClassThatImplementsMyProtocol; If you state this in your code, then any class that "conforms" to the protocol MyProtocol can be used in the variable instanceOfClassThatImplementsMyProtocol. This means that the code that uses this variable knows that it can use whichever methods are defined in MyProtocol with this particular variable, regardless of what class it is. This is a great way of avoi

Categories : IOS

Can I define 2 delegates with the same name but different parameters?
No, you cannot overload a delegate. Overloads are selected when there is type information available to the compiler to pick one... but with a delegate, you are supplying the type information and the compiler would have no way to select from overloads. If you want a family of similar delegate types, you can use generics. public delegate int EnumWindowsCallback<LParamType>(System.IntPtr hWnd, LParamType lParam); Now you can define overloaded p/invoke signatures which accept different delegate types EnumWindowsCallback<int>, EnumWindowsCallback<IntPtr>, etc.

Categories : C#

Objective-c Delegates can't understand how to use them
As Apple points out in its IOS tutorial, a delegate exists not to pass data from one part of your view to another, but to let your application react when the user causes an event to occur. For example, the user is editing something, and then tries to close the editing window. The system will send a windowShouldClose: message to the window's delegate. The delegate, if it exists and can can accept the message, can warn the user that he has unsaved edits and ask him whether to close the editing window or not. Delegates are usually declared as something like id <NSWindowDelegate> and implement that protocol. Your controllers should just pass the data themselves. That's just ordinary programming.

Categories : Objective C

VB.NET - Dictionary of strings and delegates
You have to look at Reflection. Search on the NET there are plenty of examples in VB.NET too. The strategy I can suggest is having a class implementing the functions Add Subtract etc and use the reflection GetMethod() and Invoke() to call them according to the command string. an example could be: Type type = calcobject.GetType(); MethodInfo method = type.GetMethod(RoutineName); if (method != null) { method.Invoke(this, ...parameters...); } Using a dictionary of delegates would be probably better but it does not satisfy you request of automatic binding: you need to manually add the new function in the dictionary when you decide to extend the function your interpreter understand. You can even fill the dictionary automatically; but in this case reflection come up again.

Categories : Vb.Net

Null all delegates using reflections
If type is the type of object where the delegate fields are, try this: var fields = type.GetFields(BindingFlags.Static | BindingFlags.NonPublic); fields = fields.Where(f => f.FieldType.BaseType == typeof(System.MulticastDelegate)); foreach (FieldInfo fi in fields) { fi.SetValue(null, null); } First null in SetValue means it's a static field, second one is for setting the value of the field to null.

Categories : C#

Ordering delegates with various datatypes
You can do the simple solution: public IEnumerable<Album> Get(Func<Album, object> orderingDelegate) { return _context.Albums.OrderBy(orderingDelegate); }

Categories : C#

UIScrollView not responding to delegates
I suggest that you subclass your UIScrollView object and add your touch events inside of it like below.. canvasObject.h #import <UIKit/UIKit.h> @interface canvasObject : UIScrollView @end canvasObject.m #import "canvasObject.h" @implementation canvasObject - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.canCancelContentTouches = false; } return self; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *) event { //Do Stuff } - (BOOL)textViewShouldBeginEditing:(UITextView *)textView { return YES; } @end Then link your UIScrollView using the identity inspector in interface builder to the new scroll view subclass like below..

Categories : IOS

Delegates and native methods
I guess you want a generic method: T CreateDelegate<T>(string procName) where T : class { IntPtr ptr; ptr = Kernel32Methods.GetProcAddress (libHandle, procName); if (ptr != IntPtr.Zero) { return (T)(object)Marshal.GetDelegateForFunctionPointer(ptr, typeof (T)); } return null; } Unfortunately, you can't constrain T to a delegate, so you first have to cast the result of GetDelegateForFunctionPointer to object before casting it to T. Usage: createInstance = CreateDelegate<st_createInstance>("_soundtouch_createInstance@0"); destroyInstance = CreateDelegate<st_destroyInstance>("_soundtouch_destroyInstance@4");

Categories : C#

Are these points about delegates in IOS correct? Yes or no?
1,2 - yes 3 - can call any method of MyProtocol, 4 - correct. 5 - almost right, a very good explanation can be found here delegate and controllers

Categories : IOS

Continuation with Tasks (instead of delegates)
To me, it seems like you're asking the wrong question. A queue of tasks like this is an unusual requirement. We don't know anything about the actual problem you're trying to solve, so we can't suggest better approaches. ContinueWith is intended for dynamic parallel processing, so it doesn't quite fit in with async code. However, you can use ContinueWith paired with Unwrap to sort-of emulate the behavior of await (if you ignore how await interacts with the current context). So you can simplify your queue of tasks solution as such: private Task QueueTask(Func<Task> futureTask) { _lastTask = _lastTask.ContinueWith(t => futureTask()).Unwrap(); return _lastTask; } However, there are probably better solutions. If the purpose of the queue is to provide exclusive access, a Se

Categories : C#

VB.NET Delegates and Invoke - can somebody explain these to me?
InvokeRequired asks 'Am I on the right thread?', if so carry on, else I need a delegate - in your code you see a lambda Sub Invoke(Sub() LblStatus.Text = statusText) The other way this could work is to direct the result to a diff Sub routine(where the delegate has crossed over to the correct thread), but here we are able to run a Sub inside the Invoke method itself - just a simpler way to do it. A delegate is required any time you use a separate thread to do work async. Invoke - MSDN

Categories : Vb.Net

Replacing Func with delegates C#
public delegate void Action(); public delegate void Action<T>(T t); public delegate void Action<T, U>(T t, U u); public delegate void Action<T, U, V>(T t, U u, V v); public delegate TResult Func<TResult>(); public delegate TResult Func<T, TResult>(T t); public delegate TResult Func<T, U, TResult>(T t, U u); public delegate TResult Func<T, U, V, TResult>(T t, U u, V v); public delegate TResult Func<T, U, V, W, TResult>(T t, U u, V v, W w);

Categories : C#

Calling delegates without arguments in VB.NET
I'm guessing here, so please give it a try: Instead of: For Each t As ProcessThread In p.Threads EnumThreadWindows(t.Id, MyEnumThreadWindowsProc, IntPtr.Zero) Next Try: For Each t As ProcessThread In p.Threads Dim returnMyEnumThreadWindowsProc As Object returnMyEnumThreadWindowsProc = MyEnumThreadWindowsProc ( ... ) EnumThreadWindows(t.Id, returnMyEnumThreadWindowsProc , IntPtr.Zero) Next I know that VB.NET doesn't do anonymous functions like C# does, but I am not sure how the alternative works.

Categories : C#

Multiple App delegates with storyboard
Try these sites; I cannot guarantee you will immediately find what your looking for, but as a fellow person working his way through app development, I'm sure you know how important it is to patiently and thoroughly analyze any helpful material. https://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/AppArchitecture/AppArchitecture.html https://developers.facebook.com/docs/ios/ios-6/

Categories : Misc

Handling two UITextFields and delegates
change your method as you pass the delegate to your property it will automatically identify from which textField method is called: - (BOOL)textFieldShouldReturn:(UITextField *)textField { // Removes the keyboard from the screen [textField resignFirstResponder]; return YES; }

Categories : Objective C

using delegates in an array initialization
You said you have a struct OpcodeHandler that you want to create an array of. Now I don't know what else the OpcodeHandler does, but I'll suggest something simpler: Dictionary<string, Action<PacketData>> OpcodeHandlers = new Dictionary<string, Action<PacketData>>(); This is a dictionary of delegates. You can add functions to it like so: OpcodeHandlers["someopcodenamehere"] = Somefunctionname; and call the functions like so: OpcodeHandlers["someopcodenamehere"](packetData); Edit: You can also fill the Dictionary like this: Dictionary<string, Action<PacketData>> OpcodeHandlers = new Dictionary<string, Action<PacketData>> { { "functionName1", function1 }, { "functionName2", function2 } };

Categories : C#

Correct highlighting with qt custom delegates
Please try below code, It will work. Set drawControl with take care to draw dashed line( Let Qt take care it internally ) when selected. Fixed( Dashed line, Text color and multiline ) while selecting cell. void MatchDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItemV4 opt = option; initStyleOption(&opt, index); const QWidget *widget = option.widget; QString str = qvariant_cast<QString>(index.data())+ " "; str += QString::number(qvariant_cast<float>(index.data(Qt::UserRole))); opt.text = ""; //option QStyle *style = widget ? widget->style() : QApplication::style(); if (option.state & QStyle::Sta

Categories : C++

Delegates issue in source controller
You're missing an opening parenthesis: -(void)playerDetailsViewController: PlayerDetailsViewController *)controller ... should be: -(void)playerDetailsViewController:(PlayerDetailsViewController *)controller ...

Categories : IOS

Separating delegates from ViewController to own classes
Implement a class responsible for delegate methods: @interface DelegateManager : NSObject <MKMapViewDelegate, HttpClientDelegate, CLLocationManagerDelegate, NSFetchedResultsControllerDelegate> -(id)initWithViewController:(ViewController*)vc; @property (weak) ViewController *delegate; @end In your ViewController: @interface ViewController : UIViewController -(void)doSomething; @end In your ViewController, create an instance of DelegateManager with self as parameter. Set all your delegates' target to your DelegateManager. In the delegate methods of your DelegateManager, call [self.delegate doSomething]; to communicate back to your ViewController.

Categories : Iphone

Delegates and Events with multiple classes
Your approach is sound except for two details. First, a NullPointerException will occur if your event is raised before any handlers are added. You can get around this in one of two ways. 1) Make a local copy (to avoid race condition) and check it for null: var showMessage = OnShowMessage; if (showMessage != null) { showMessage(this, e); } 2) Initialize your event to an empty delegate: public event ShowMessage OnShowMessage = delegate { }; Second, you do not need to declare your own delegate in this case. You can simply create a standard EventHandler with your own event args: public event EventHandler<Form1.AnswerEventArgs> OnShowMessage = delegate { }; See How to: Publish Events that Conform to .NET Framework Guidelines for more information.

Categories : C#

Delegates and object retention objective-c (iOS)
Wow, this is some convoluted code. I'm just guessing that the problem might be in this line: [parser setDelegate: [[[Route53HostedZoneUnmarshaller alloc] initWithCaller:self withParentObject:self.response.hostedZones withSetter:@selector(addObject:)] autorelease] ]; I don't see what parser's type is, but in Objective-C in general delegates are not retained. So the whole Route53HostedZoneUnmarshaller may be garbage by the time it is used. Try removing the call to autorelease and store the delegate object in a property until the parsing process is finished.

Categories : IOS

delegates and gestureRecognizers for a UIView Subclass
You should add the gesture on button and not on to the subview of button. UILongPressGestureRecognizer *singlePress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handlePress:)]; [self.button addGestureRecognizer:singlePress]; There is no need to add following line: singlePress.delegate = self;

Categories : Iphone

How to use delegates with Application.OpenForms in a different thread
Rather than using Focused, which I don't think works very well for Forms, try using Form.ActiveForm: Dim frmCurrentForm As Form frmCurrentForm = Form.ActiveForm If Not frmCurrentForm Is Nothing Then Dim action As Action(Of Form) action = Sub(form) Dim failedLoginForm As New Form2 failedLoginForm.setError("failed blah blah") failedLoginForm.StartPosition = FormStartPosition.CenterParent failedLoginForm.ShowDialog(form) End Sub If (frmCurrentForm.InvokeRequired) Then frmCurrentForm.Invoke(action, New Object() {frmCurrentForm}) Else action(frmCurrentForm) End If End If

Categories : Vb.Net

Can I use method pointers in c++ alike delegates in c#?
In C++ you can use boost bind to bind the function call: void X::DoSomethingA(){ ExtractedMethod( boost::bind(&X::ADoer, pInstance) ); } The pInstance is needed if X::ADoer isn't a static member of class X. For the function type you'd use either std::function (latest C++) or boost::function. typedef std::function< void(TypeOfABCResult) > MyDelegateType; void X::ExtractedMethod( MyDelegateType delegate ) { ... } And this isn't a workaround. It IS how you do it in C++, and it works every bit similar to how it works in C# with delegates.

Categories : C++

Why can't I set the delegates of these UITextFields when the ViewController is being initialized?
Inside init method, the views haven't been loaded. All the visual setup must be done further on in the viewController's lifecycle, at least into the viewDidLoad method. Or in case that you don't go for a .xib solution, you can do it while loading the view manually, into the loadView method. So, both labels are nil into the init method, and the delegate can't be set.

Categories : IOS

Passing parameter between classes via delegates or...?
You're going to want to use threads. You'll fire off a thread in StateMonitor that loops based on a boolean. Then set that boolean from SimpleScene when you want to do something when that flag is true. There are tons of examples out there. Check here: http://msdn.microsoft.com/en-us/library/7a2f3ay4(v=vs.90).aspx Worker = StateMonitor WorkerThreadExample = SimpleScene

Categories : C#

iOS - can the number of delegates become a memory issue
As long as the same main view is the delegate for all of your objects, the only memory consumption in this pattern are your newly created objects. The delegate references cost nothing in terms of reference, as they are just pointers to your existing main view controller. With that said, in some circumstances, people do create specialized objects to act as delegates and if you follow that pattern (where you would allocate and maintain a separate delegate object for each "other" object), then you would see consumption and this pattern sometimes leads to leaks depending on how ownership is managed/mismanaged. But, for the case described above, it should not be a problem.

Categories : IOS

calling custom delegates not working
Make sure you're actually assigning the delegate property to MainController. For instance, wherever you've initialized Example, you need to set the delegate property: Example *example = [[Example alloc] init]; example.delegate = self; // Use this if you're initializing Example in MainController If you're not initializing Example in MainController, instead of "self" use the MainController instance.

Categories : Objective C

VB.net, Invoke, delegates, and threading. Can't figure out how to use them across classes.
I'm not certain I understand what you are trying to do, but building upon your code, you can set the label safely ("thread-safely") by using the following code: Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim t1 As New Threading.Thread(AddressOf Count) t1.IsBackground = True t1.Start(100) End Sub Private Sub Count(ByVal Max As Object) If TypeOf Max Is Integer Then Dim class2 As New Class2 class2.Count(CInt(Max), AddressOf SetLabelText) End If End Sub Private Sub SetLabelText(ByVal text As String) If Label1.InvokeRequired Then Label1.Invoke(New SetText(AddressOf SetLabelText), text) Else

Categories : Vb.Net

Is it possible to have delegates marshalled as proxies when they are passed across to another AppDomain?
Unfortunately it is not directly possible to make the delegate itself a proxy. Delegates are always by-value objects for the purpose of remoting. I find that a strange design decision as I think it goes against the logical semantics of delegates, but that’s another matter. To solve this, I had to wrap the delegate into a class that I can make a MarshalByRefObject so that it would be proxied. That class needs to have a method that is equivalent to invoking the delegate. To keep this clean, I decided to make that class private: private sealed class myDelegateWrapper : MarshalByRefObject { public Output Invoke(Input input) { return _delegate(input); } private Func<Input, Output> _delegate; public myDelegateWrapper(Func<Input, Output> dlgt) {

Categories : C#

iOS TablewView not showing data (delegates called)
Check if you have connected your table view from storyboard to the IBOutlet variable UITablveView in your .h file. You mentioned you have linked the cell. Not sure that is the right thing to do. Other possibility is that you have not identified your view controller on the storyboard to your class name (SecondViewController). If not working after trying/confirming these, then share your .h file too. We will be able to help more.

Categories : IOS

C# delegates to Java and asynchronous handling of methods
This is actually the old way of writing async code in C#, commonly referred to as the Async Programming Model I am not familiar enough with java, but all you really need to replicate this code is to create a method that does the action synchronously SendAggregateEvent and a means to call that asynchronously SendAggregateEventAsync More specifically to some of your questions. The delegate is only being used to encapsulate the SendAggregateEvent method so that it and its parameters can be invoked on a potentially different thread (keeping in mind that async is not necessarily multi-threaded) It goes something like this: var referenceToTaskBeingRun = BeginSomeMethod() //the above wraps the actual method and calls it, returning a reference to the task var results = EndSomeMethod(reference

Categories : C#



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.