Is there a way in xcode 4 to list all the delegate functions and automatically add a piece of code to a file?

This seems like an obvious function that should be there, but I can't find it.

For example, if my class is uitableviewdelegate, the fastest way to see all available delegation methods and add those that were interested in my implementation file?

+4
source share
1 answer

You can use the tooltip in the first link that Simon posted above to get the method signatures for the delegate. After that, adding the code is up to you.

What I like to do is select the delegate methods that I use most often and add them to the code snippet.

For example, for a UITableViewDatasource, I have a fragment called "UITableView Datasource Required Methods" containing:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"myCellName"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier] autorelease]; } //customize cell before showing it return cell; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return <#numRow#> ; } 

Then I drag this piece of code into my code whenever I create a table delegate.

+2
source

All Articles