Search Results

Search found 2441 results on 98 pages for 'delegate'.

Page 2/98 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • C# event or delegate or other solution?

    - by user295734
    Looking for some help or programmng ideas or mayeb there is some pattern that would help. Have an application that needs to fire alot of events sequentially, it could up to 100 or more unique events, it will be dynamic depeneding on the situation. Trying to find the best practice for doing this. My main idea right now is to create a list of objects iterate thru them, and fire each event. This seems wrong, or bad practice. Or maybe have one object and pass a list or params into one event? Or am I missing some feature in .NET that i could be using or implementing?

    Read the article

  • Uses of Action delegate in C#

    - by Biswanath
    I was working with the Action Delgates in C# in the hope of learning more about them and thinking where they might be useful. Has anybody used the Action Delgate, and if so why? or could you give some examples where it might be useful?

    Read the article

  • linq delegate function checking from objects

    - by Philip
    I am trying to find the list of objects which can be replaced. Class Letter{ int ID; string Name; string AdvCode; int isDeleted; } Class Replacers{ int ID; string MainAdvCode; string ReplacesAdvCode; } example data: Replacers 0 455 400 1 955 400 2 955 455 such that if a Letter has and Advcode of 455 and another has a code of 400 the 400 gets marked for deletion. And then if another Letter has a 955 then the 455 gets marked for deletion and the 400 (which is already marked) is marked for deletion. The problem is with my current code the 400 and 455 is marking itself for deletion?!?!? Public class Main{ List<Letter> Letters; List<Replacers> replaces; //select the ones to replace the replacements aka the little guys //check if the replacements replacer exists if yes mark deleted var filterMethodReplacements = new Func<Letter, bool>(IsAdvInReplacements);//Working var filterMethodReplacers = new Func<Letter, bool>(IsAdvInReplacers);//NOT WORKING???? var resReplacements=letters.Where(filterMethodReplacements);//working foreach (Letter letter in resReplacements) { //select the Replacers aka the ones that contain the little guys var resReplacers = letters.Where(filterMethodReplacers); if (resReplacers != null) letter.isDeleted = 1; } } } private bool IsAdvInReplacements(Letter letter) { return (from a in Replacables where a.ReplaceAdvCode == letter.AdvCode select a).Any(); } private bool IsAdvInReplacers(Letter letter) { //?????????????????????????????? return (from a in Replacables where a.MainAdvCode == letter.AdvCode select a).Any(); } }

    Read the article

  • Problem with anonymouse delegate within foreach

    - by geting
    public Form1() { InitializeComponent(); Collection<Test> tests = new Collection<Test>(); tests.Add(new Test("test1")); tests.Add(new Test("test2")); foreach (Test test in tests) { Button button = new Button(); button.Text = test.name; button.Click+=new EventHandler((object obj, EventArgs arg)=>{ this.CreateTest(test); }); this.flowLayoutPanel1.Controls.Add(button); } } public void CreateTest(Test test) { MessageBox.Show(test.name); } } when i click the button witch text is 'test1', the messagebox will show 'test2',but my expect is 'test1'. So ,would anyone please tell me why or what`s wrong with my code.

    Read the article

  • Avoiding EXC_BAD_ACCESS when using the delegate pattern

    - by Kenny Winker
    A have a view controller, and it creates a "downloader" object, which has a reference to the view controller (as a delegate). The downloader calls back the view controller if it successfully downloads the item. This works fine as long as you stay on the view, but if you navigate away before the download is complete I get EXC_BAD_ACCESS. I understand why this is happening, but is there any way to check if an object is still allocated? I tried to test using delegate != nil, and [delegate respondsToSelector:], but it chokes. if (!self.delegate || ![self.delegate respondsToSelector:@selector(downloadComplete:)]) { // delegate is gone, go away quietly [self autorelease]; return; } else { // delegate is still around [self.delegate downloadComplete:result]; } I know I could, a) have the downloader objects retain the view controller b) keep an array of downloaders in the view controller, and set their delegate values to nil when I deallocate the view controller. But I wonder if there is an easier way, where I just test if the delegate address contains a valid object?

    Read the article

  • Does delegate chaining have to start with a null Delegate?

    - by MCS
    In CLR via C#, Jeffrey Richter gives the following example of delegate chaining (pg. 406): internal delegate void Feedback(Int 32 value); Feedback fb1 = new Feedback(method1); // in the book, these methods Feedback fb2 = new Feedback(method2); // have different names Feedback fb3 = new Feedback(method3); Feedback fbChain = null; fbChain = (Feedback) Delegate.Combine(fbChain, fb1); fbChain = (Feedback) Delegate.Combine(fbChain, fb2); fbChain = (Feedback) Delegate.Combine(fbChain, fb3); Why does the first call to Delegate.Combine have to pass in a null Delegate? Here's how I would have thought it should be written: Feedback fbChain = (Feedback) Delegate.Combine(fb1, fb2); fbChain = (Feedback) Delegate.Combine(fbchain, fb3);

    Read the article

  • why can't I set a new instance's delegate as self?

    - by Guille10k
    I have a uipickerview, which appears with an ActionSheet. All this is in a class "MultiPicker". I create a new instance from "FirstViewController" this way: multiPicker *multiPic = [[multiPicker alloc]init]; multiPic.delegate = self; [multiPic action:aRunIndex]; And inside "multiPicker", in "action:" UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:title delegate:otroDelegate cancelButtonTitle:nil destructiveButtonTitle:@"Cancel" otherButtonTitles:@"Done", nil]; UIPickerView *pickerView = [[[UIPickerView alloc] init] autorelease]; pickerView.tag = 101; pickerView.delegate = self; pickerView.dataSource = self; pickerView.showsSelectionIndicator = YES; [actionSheet addSubview:pickerView]; [actionSheet showInView:self.view]; I need "FirstViewController" when MultiPicker finishes, so I can update a table in FirstView. I tried setting a new delegate to MultiPicker so, it tells FirstView when it finishes. But the instruction "multipic.delegate = self" in the first piece of code mades the app crash and says "Terminating due to uncaught exception". If I simply put all "MultiPicker" code inside FirstViewController class, not in a separate one, the action sheet stay blocked when I try to push a button different from "Cancel" Any idea? Thank u

    Read the article

  • iOS - Unit tests for KVO/delegate codes

    - by ZhangChn
    I am going to design a MVC pattern. It could be either designed as a delegate pattern, or a Key-Value-Observing(KVO), to notify the controller about changing models. The project requires certain quality control procedures to conform to those verification documents. My questions: Does delegate pattern fit better for unit testing than KVO? If KVO fits better, would you please suggest some sample codes?

    Read the article

  • Create a new delegate class for each asynchronous image download?

    - by Charles S.
    First, I'm using an NSURLConnection to download JSON data from twitter. Then, I'm using a second NSURLConnection to download corresponding user avatar images (the urls to the images are parsed from the first data download). For the first data connection, I have my TwitterViewController set as the NSURLConnection delegate. I've created a separate class (ImageDownloadDelegate) to function as the delegate for a second NSURLConnection that handles the images. After the tweets are finished downloading, I'm using this code to get the avatars: for(int j=0; j<[self.tweets count]; j++){ ImageDownloadDelegate *imgDelegate = [[ImageDownloadDelegate alloc] init]; Tweet *myTweet = [self.tweets objectAtIndex:j]; imgDelegate.tweet = myTweet; imgDelegate.table = timeline; NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:myTweet.imageURL] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60]; imgConnection = [[NSURLConnection alloc] initWithRequest:request delegate:imgDelegate]; [imgDelegate release]; } So basically a new instance of the delegate class is created for each image that needs to be downloaded. Is this the best way to go about this? But then there's no way to figure out which image is associate with which tweet, correct? The algorithm works fine... I'm just wondering if I'm going about it the most efficient way.

    Read the article

  • (Cocoa) Can I Subclass and Delegate at the same time?

    - by Alvin
    @interface ClassB <ClassADelegate> : ClassA id <ClassBDelegate> delegate; @end As the code says, ClassB subclasses from ClassA and handles the formation protocol of Class A. However, the variable "delegate" will be duplicated. (ClassA also has "delegate") In fact, it can be done without subclassing, but it seems the code is cumbersome, i.e., to use a variable/function of ClassA, I need to write [[ClassB classA] doSomething] instead of [classB doSomething], where doSomething: is a function of ClassA. Are there any tidy way for me to do that?

    Read the article

  • How to deal with delegate method calling back the object who send the message ?

    - by olipion
    I have two object: @protocol ObjectADelegate - (void)objectAfirst:(ObjectA *)obj; - (void)objectAsecond:(ObjectA *)obj; @end @interface ObjectA : NSObject { id<ObjectADelegate> delegate; - (void)callSecond { [self.delegate objectAsecond:self]; } @end @interface ObjectB : NSObject <ObjectADelegate>{ ObjectA *myObjectA; } @implementation ObjectB - (void)objectAfirst:(ObjectA *)obj { // First is finished, do second [obj callSecond]; } - (void)objectASecond:(ObjectA *)obj { // Do my stuff } @end As you can see in the code, when ObjectA send the message objectAfirst to its delegate, objectb use again objectA methods that result in objecta calling back objectb. It means that what first fire objectAfirst is not finished but objectA send the objectAsecond message. Could it be a problem ? Any way to let delay message handling in objectB ? for example, something like using [obj performSelector:@selector(callSecond) afterDelay:0.01]; instead of [obj callSecond]; ?

    Read the article

  • Delegate performance of Roslyn Sept 2012 CTP is impressive

    - by dotneteer
    I wanted to dynamically compile some delegates using Roslyn. I came across this article by Piotr Sowa. The article shows that the delegate compiled with Roslyn CTP was not very fast. Since the article was written using the Roslyn June 2012, I decided to give Sept 2012 CTP a try. There are significant changes in Roslyn Sept 2012 CTP in both C# syntax supported as well as API. I found Anoop Madhisidanan’s article that has an example of the new API. With that, I was able to put together a comparison. In my test, the Roslyn compiled delegate is as fast as C# (VS 2012) compiled delegate. See the source code below and give it a try. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; using Roslyn.Compilers; using Roslyn.Scripting.CSharp; using Roslyn.Scripting; namespace RoslynTest { class Program { public Func del; static void Main(string[] args) { Stopwatch stopWatch = new Stopwatch(); Program p = new Program(); p.SetupDel(); //Comment out this line and uncomment the next line to compare //p.SetupScript(); stopWatch.Start(); int result = DoWork(p.del); stopWatch.Stop(); Console.WriteLine(result); Console.WriteLine("Time elapsed {0}", stopWatch.ElapsedMilliseconds); Console.Read(); } private void SetupDel() { del = (s, i) => ++s; } private void SetupScript() { //Create the script engine //Script engine constructor parameters go changed var engine=new ScriptEngine(); //Let us use engine's Addreference for adding the required //assemblies new[] { typeof (Console).Assembly, typeof (Program).Assembly, typeof (IEnumerable<>).Assembly, typeof (IQueryable).Assembly }.ToList().ForEach(asm => engine.AddReference(asm)); new[] { "System", "System.Linq", "System.Collections", "System.Collections.Generic" }.ToList().ForEach(ns=>engine.ImportNamespace(ns)); //Now, you need to create a session using engine's CreateSession method, //which can be seeded with a host object var session = engine.CreateSession(); var submission = session.CompileSubmission>("new Func((s, i) => ++s)"); del = submission.Execute(); //- See more at: http://www.amazedsaint.com/2012/09/roslyn-september-ctp-2012-overview-api.html#sthash.1VutrWiW.dpuf } private static int DoWork(Func del) { int result = Enumerable.Range(1, 1000000).Aggregate(del); return result; } } }  Since Roslyn Sept 2012 CTP is already over a year old, I cannot wait to see a new version coming out.

    Read the article

  • Accessing UI elements from delegate function in Windows Phone 7

    - by EpsilonVector
    I have the following scenario: a page with a bunch of UI elements (grids, textblocks, whatever), and a button that when clicked launches an asynchronous network transaction which, when finished, launches a delegate function. I want to reference the page's UI elements from that delegate. Ideally I would like to do something like currentPage.getUIElementByName("uielement").insert(data), or even uielement.insert(data), or something similar. Is there a way to do this? No matter what I try an exception is being thrown saying that I don't have permissions to access that element. Is there a more correct way to handle updating pages with data retrieved over network?

    Read the article

  • Does "delegate" mean a type or an object?

    - by Michal Czardybon
    Reading from MSDN: "A delegate is a type that references a method. Once a delegate is assigned a method, it behaves exactly like that method." Does then "delegate" mean a type or an object?! ...It cannot be both. It seems to me that the single word is used in two different meanings: a type containing a reference to a method of some specified signature, an object of that type, which can be actually called like a method. I would prefer a more precise vocabulary and use "delegate type" for the first case. I have been recently reading a lot about events and delegates and that ambiguity was making me confused many times. Some other uses of "delegate" word in MSDN in the first meaning: "Custom event delegates are needed only when an event generates event data" "A delegate declaration defines a class that is derived from the class System.Delegate" Some other uses of "delegate" word in MSDN in the second meaning: "specify a delegate that will be called upon the occurrence of some event" "Delegates are objects that refer to methods. They are sometimes described as type-safe function pointers" What do you think? Why did people from Microsoft introduced this ambiguity? Am I the only person to have conceptual problems with different notions being referenced with the same word.

    Read the article

  • Action delegate in C#

    - by Jalpesh P. Vadgama
    In last few posts about I have written lots of things about delegates and this post is also part of that series. In this post we are going to learn about Action delegates in C#.  Following is a list of post related to delegates. Delegates in C#. Multicast Delegates in C#. Func Delegates in C#. Action Delegates in c#: As per MSDN action delegates used to pass a method as parameter without explicitly declaring custom delegates. Action Delegates are used to encapsulate method that does not have return value. C# 4.0 Action delegates have following different variants like following. It can take up to 16 parameters. Action – It will be no parameter and does not return any value. Action(T) Action(T1,T2) Action(T1,T2,T3) Action(T1,T2,T3,T4) Action(T1,T2,T3,T4,T5) Action(T1,T2,T3,T4,T5,T6) Action(T1,T2,T3,T4,T5,T6,T7) Action(T1,T2,T3,T4,T5,T6,T7,T8) Action(T1,T2,T3,T4,T5,T6,T7,T8,T9) Action(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10) Action(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11) Action(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12) Action(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13) Action(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14) Action(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15) Action(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16) So for this Action delegate you can have up to 16 parameters for Action.  Sound interesting!!… Enough theory now. It’s time to implement real code. Following is a code for that. using System; using System.Collections.Generic; namespace DelegateExample { class Program { static void Main(string[] args) { Action<String> Print = p => Console.WriteLine(p); Action<String,String> PrintAnother = (p1,p2)=> Console.WriteLine(string.Format("{0} {1}",p1,p2)); Print("Hello"); PrintAnother("Hello","World"); } } } In the above code you can see that I have created two Action delegate Print and PrintAnother. Print have one string parameter and its printing that. While PrintAnother have two string parameter and printing both the strings via Console.Writeline. Now it’s time to run example and following is the output as expected. That’s it. Hope you liked it. Stay tuned for more updates!!

    Read the article

  • C# Delegate under the hood question.

    - by Ted
    Hi Guys I was doing some digging around into delegate variance after reading the following tquestion in SO. "delegate-createdelegate-and-generics-error-binding-to-target-method" (sorry not allowed to post more than one hyperlink as a newbie here!) I found a very nice bit of code from Barry kelly at https://www.blogger.com/comment.g?blogID=8184237816669520763&postID=2109708553230166434 Here it is (in a sugared-up form :-) using System; namespace ConsoleApplication4 { internal class Base { } internal class Derived : Base { } internal delegate void baseClassDelegate(Base b); internal delegate void derivedClassDelegate(Derived d); internal class App { private static void Foo1(Base b) { Console.WriteLine("Foo 1"); } private static void Foo2(Derived b) { Console.WriteLine("Foo 2"); } private static T CastDelegate<T>(Delegate src) where T : class { return (T) (object) Delegate.CreateDelegate( typeof (T), src.Target, src.Method, true); // throw on fail } private static void Main() { baseClassDelegate a = Foo1; // works fine derivedClassDelegate b = Foo2; // works fine b = a.Invoke; // the easy way to assign delegate using variance, adds layer of indirection though b(new Derived()); b = CastDelegate<derivedClassDelegate>(a); // the hard way, avoids indirection b(new Derived()); } } } I understand all of it except this one (what looks very simple) line. b = a.Invoke; // the easy way to assign delegate using variance, adds layer of indirection though Can anyone tell me: how it is possible to call invoke without passing the param required by the static function. When is going on under the hood when you assign the return value from calling invoke What does Barry mean by extra indirection (in his comment)

    Read the article

  • c# delegate and abstract class

    - by BeraCim
    Hi all: I currently have 2 concrete methods in 2 abstract classes. One class contains the current method, while the other contains the legacy method. E.g. // Class #1 public abstract class ClassCurrent<T> : BaseClass<T> where T : BaseNode, new() { public List<T> GetAllRootNodes(int i) { //some code } } // Class #2 public abstract class MyClassLegacy<T> : BaseClass<T> where T : BaseNode, new() { public List<T> GetAllLeafNodes(int j) { //some code } } I want the corresponding method to run in their relative scenarios in the app. I'm planning to write a delegate to handle this. The idea is that I can just call the delegate and write logic in it to handle which method to call depending on which class/project it is called from (at least thats what I think delegates are for and how they are used). However, I have some questions on that topic (after some googling): 1) Is it possible to have a delegate that knows the 2 (or more) methods that reside in different classes? 2) Is it possible to make a delegate that spawns off abstract classes (like from the above code)? (My guess is a no, since delegates create concrete implementation of the passed-in classes) 3) I tried to write a delegate for the above code. But I'm being technically challenged: public delegate List GetAllNodesDelegate(int k); GetAllNodesDelegate del = new GetAllNodesDelegate(ClassCurrent.GetAllRootNodes); I got the following error: An object reference is required for the non-static field, method, property ClassCurrent<BaseNode>.GetAllRootNodes(int) I might have misunderstood something... but if I have to manually declare a delegate at the calling class, AND to pass in the function manually as above, then I'm starting to question whether delegate is a good way to handle my problem. Thanks.

    Read the article

  • Why aren't Admob click callback delegate methods not getting called?

    - by executor21
    I'm integrating the latest version of the admob sdk (version 20100412) into my app. The ads get displayed, but I need the app to make some changes when an ad is clicked and admob displays a full-screen browser. However, none of the callback methods (willPresentFullScreenModal, didPresentFullScreenModal, willDismissFullScreenModal, and didDismissFullScreenModal) are called, even though other delegate methods are. Why aren't these callbacks being made? They were in the previous versions of the SDK, and the sample app doesn't use them, so it's no help.

    Read the article

  • Using delegates in C# (Part 2)

    - by rajbk
    Part 1 of this post can be read here. We are now about to see the different syntaxes for invoking a delegate and some c# syntactic sugar which allows you to code faster. We have the following console application. 1: public delegate double Operation(double x, double y); 2:  3: public class Program 4: { 5: [STAThread] 6: static void Main(string[] args) 7: { 8: Operation op1 = new Operation(Division); 9: double result = op1.Invoke(10, 5); 10: 11: Console.WriteLine(result); 12: Console.ReadLine(); 13: } 14: 15: static double Division(double x, double y) { 16: return x / y; 17: } 18: } Line 1 defines a delegate type called Operation with input parameters (double x, double y) and a return type of double. On Line 8, we create an instance of this delegate and set the target to be a static method called Division (Line 15) On Line 9, we invoke the delegate (one entry in the invocation list). The program outputs 5 when run. The language provides shortcuts for creating a delegate and invoking it (see line 9 and 11). Line 9 is a syntactical shortcut for creating an instance of the Delegate. The C# compiler will infer on its own what the delegate type is and produces intermediate language that creates a new instance of that delegate. Line 11 uses a a syntactical shortcut for invoking the delegate by removing the Invoke method. The compiler sees the line and generates intermediate language which invokes the delegate. When this code is compiled, the generated IL will look exactly like the IL of the compiled code above. 1: public delegate double Operation(double x, double y); 2:  3: public class Program 4: { 5: [STAThread] 6: static void Main(string[] args) 7: { 8: //shortcut constructor syntax 9: Operation op1 = Division; 10: //shortcut invoke syntax 11: double result = op1(10, 2); 12: 13: Console.WriteLine(result); 14: Console.ReadLine(); 15: } 16: 17: static double Division(double x, double y) { 18: return x / y; 19: } 20: } C# 2.0 introduced Anonymous Methods. Anonymous methods avoid the need to create a separate method that contains the same signature as the delegate type. Instead you write the method body in-line. There is an interesting fact about Anonymous methods and closures which won’t be covered here. Use your favorite search engine ;-)We rewrite our code to use anonymous methods (see line 9): 1: public delegate double Operation(double x, double y); 2:  3: public class Program 4: { 5: [STAThread] 6: static void Main(string[] args) 7: { 8: //Anonymous method 9: Operation op1 = delegate(double x, double y) { 10: return x / y; 11: }; 12: double result = op1(10, 2); 13: 14: Console.WriteLine(result); 15: Console.ReadLine(); 16: } 17: 18: static double Division(double x, double y) { 19: return x / y; 20: } 21: } We could rewrite our delegate to be of a generic type like so (see line 2 and line 9). You will see why soon. 1: //Generic delegate 2: public delegate T Operation<T>(T x, T y); 3:  4: public class Program 5: { 6: [STAThread] 7: static void Main(string[] args) 8: { 9: Operation<double> op1 = delegate(double x, double y) { 10: return x / y; 11: }; 12: double result = op1(10, 2); 13: 14: Console.WriteLine(result); 15: Console.ReadLine(); 16: } 17: 18: static double Division(double x, double y) { 19: return x / y; 20: } 21: } The .NET 3.5 framework introduced a whole set of predefined delegates for us including public delegate TResult Func<T1, T2, TResult>(T1 arg1, T2 arg2); Our code can be modified to use this delegate instead of the one we declared. Our delegate declaration has been removed and line 7 has been changed to use the Func delegate type. 1: public class Program 2: { 3: [STAThread] 4: static void Main(string[] args) 5: { 6: //Func is a delegate defined in the .NET 3.5 framework 7: Func<double, double, double> op1 = delegate (double x, double y) { 8: return x / y; 9: }; 10: double result = op1(10, 2); 11: 12: Console.WriteLine(result); 13: Console.ReadLine(); 14: } 15: 16: static double Division(double x, double y) { 17: return x / y; 18: } 19: } .NET 3.5 also introduced lambda expressions. A lambda expression is an anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types. We change our code to use lambda expressions. 1: public class Program 2: { 3: [STAThread] 4: static void Main(string[] args) 5: { 6: //lambda expression 7: Func<double, double, double> op1 = (x, y) => x / y; 8: double result = op1(10, 2); 9: 10: Console.WriteLine(result); 11: Console.ReadLine(); 12: } 13: 14: static double Division(double x, double y) { 15: return x / y; 16: } 17: } C# 3.0 introduced the keyword var (implicitly typed local variable) where the type of the variable is inferred based on the type of the associated initializer expression. We can rewrite our code to use var as shown below (line 7).  The implicitly typed local variable op1 is inferred to be a delegate of type Func<double, double, double> at compile time. 1: public class Program 2: { 3: [STAThread] 4: static void Main(string[] args) 5: { 6: //implicitly typed local variable 7: var op1 = (x, y) => x / y; 8: double result = op1(10, 2); 9: 10: Console.WriteLine(result); 11: Console.ReadLine(); 12: } 13: 14: static double Division(double x, double y) { 15: return x / y; 16: } 17: } You have seen how we can write code in fewer lines by using a combination of the Func delegate type, implicitly typed local variables and lambda expressions.

    Read the article

  • Using CALayer Delegate

    - by Shaun Budhram
    I have a UIView whose layers will have sublayers. I'd like to assign delegates for each of those sublayers, so the delegate method can tell the layer what to draw. My question is: What should I provide as CALayer's delegate? The documentation says not to use the UIView the layers reside in, as this is reserved for the main CALayer of the view. But, creating another class just to be the delegate of the CALayers I create defeats the purpose of not subclassing CALayer. What are people typically using as the delegate for CALayer? Or should I just subclass? Also, why is it that the class implementing the delegate methods doesn't have to conform to some sort of CALayer protocol? That's a wider overarching question I don't quite understand. I thought all classes requiring implementation of delegate methods required a protocol specification for implementers to conform to.

    Read the article

  • Why aren't Admob click callback delegate methods getting called?

    - by executor21
    I'm integrating the latest version of the admob sdk (version 20100412) into my app. The ads get displayed, but I need the app to make some changes when an ad is clicked and admob displays a full-screen browser. However, none of the callback methods (willPresentFullScreenModal, didPresentFullScreenModal, willDismissFullScreenModal, and didDismissFullScreenModal) are called, even though other delegate methods are. Why aren't these callbacks being made? They were in the previous versions of the SDK, and the sample app doesn't use them, so it's no help. EDIT: removed the double negative from the question title

    Read the article

  • NSXMLParser 's delegate and memory leak

    - by dizzy_fingers
    Hello, I am using a NSXMLParser class in my program and I assign a delegate to it. This delegate, though, gets retained by the setDelegate: method resulting to a minor, yet annoying :-), memory leak. I cannot release the delegate class after the setDelegate: because the program will crash. Here is my code: self.parserDelegate = [[ParserDelegate alloc] init]; //retainCount:1 self.xmlParser = [[NSXMLParser alloc] initWithData:self.xmlData]; [self.xmlParser setDelegate:self.parserDelegate]; //retainCount:2 [self.xmlParser parse]; [self.xmlParser release]; ParserDelegate is the delegate class. Of course if I set 'self' as the delegate, I will have no problem but I would like to know if there is a way to use a different class as delegate with no leaks. Thank you in advance.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >