Tag: delegates

Implement Delegate at Run Time?

I have a universal view controller class which all of the view controller classes in my app inherit from which has the following loadView method: – (void) loadView { if (viewType == UIStandardViewControllerViewTypeUIView) { UIView *view = [[UIView alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame]]; [self setView: view]; [view release]; } else if (viewType == UIStandardViewControllerViewTypeUIScrollView) { […]

Delegate as external class in Objective-C

I’m creating a simple project for iPhone, using Xcode and Interface Builder. While I understand what a delegate is, I have a problem with using it. I have an UITextField in my interface. It displays keyboard when user taps on it, but I need to program manually how to hide keyboard. It can be done […]

Objective-C @protocol equivalent in C++

Class A has an instance of class B as a member. Sometimes the instance of class B wants to talk to class A. In Objective-C I can do: // A.h @interface A : NSObject <BDelegate> @property (nonatomic, retain) B *b; @end // A.m – (void) classBsays { } // B.h @protocol BDelegate – (void) classBsays; […]

When using delegates, need better way to do sequential processing

I have a class WebServiceCaller that uses NSURLConnection to make asynchronous calls to a web service. The class provides a delegate property and when the web service call is done, it calls a method webServiceDoneWithXXX on the delegate. There are several web service methods that can be called, two of which are say GetSummary and […]

Delegate events for NSTextField in a view-based NSOutlineView?

I have a flawless functioning view-based NSOutlineView with a proper set-up datasource in my project. Now I want to allow the user to change certain entries. So I made the NSTextField in the IB editable. For a cell-based NSOutlineView you can use the delegate method outlineView:setObjectValue:forTableColumn:byItem: however it’s not available for a view-based NSOutlineView as […]

How to set a delegate in a different class

I’m working with NSXMLParser that parses a xml document. You have to set the delegate which we would be called every time the parser finds an element. The examples I’ve looked at all set the delegate to be the same class that’s createing: NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:filename]; [parser setDelegate: self]; Other examples set […]

Juggling multiple UINavigationControllers using the App Delegate and ensuring UINavigationController correctly deallocs

I have a app which uses two UINavigationControllers – one for the menu system and one for the actual game. A common UINavigationController is declared in my appDelegate. When the app loads, it either loads the Menu or the Game’s UINavigationController. And of course the player can then navigate between the two. When going from […]

NSTextField delegate notifications — how to get text?

I’ve been trying to learn to use Xcode, but I’m getting confused with how to register that NSTextField has changed. Essentially, I have an NSTextField and a button. Clicking the button does stuff with the text in the field. However, I want to be able to get the text of the field without needing to […]

Why do we set delegate to nil at dealloc if the object is going to be destroyed anyway?

-(void) scrollViewDidScroll:(UIScrollView *)scrollView { PO(NSStringFromCGPoint(self.tableView.contentOffset)); PO(NSStringFromUIEdgeInsets(self.tableView.contentInset)); while(false); } -(void)dealloc { PO(NSStringFromClass([self class])); PO(@”Deallocated”); self.tableView.delegate=nil; } Here I need to set self.tableView.delegate = nil to avoid error. I am aware, from my previous question, that self.tableView.delegate won’t automatically become nill when the delegate is destroyed. That’s because the type of delegate is assign reference instead of […]

Can someone please explain delegates in objective-c?

I have been using Objective-C for a while and pretty much understand most of its features. However, the concept of delegates eludes me. Can someone please give a succinct and easy to comprehend explanation of what delegates are, how they are used in the iPhone SDK, and how I can best make use of them […]