0
votes

yesterday I just asked following question.


How to customize tableView Section View - iPhone
I found some new method.

Even in apple documentation I didn't found this method.

Is it some thing like hidden methods?

Does anybody provides all methods listing? Including sample code.

Say for example. UITableView methods

Whenever I insert tableView in my view Controller.

I have to either type or copy from some where.

If I want to include picker I have to find out UIPicker methods, sameway Alertview, ActionSheet, Tab Bar Controller all has different methods.

Isn't it possible, like if we include A tableView in our ViewController, Automatically all tableview methods are added to .m file.

(For example, A navigation based application has all tableView methods in rootview controller by default)

Let Me Clarify Again,

"I need proper source where all methods (like rootview controller has almost all table methods) "

So, when ever I want to add any control I just copy the code & add to my Project.

The reason Behind this "We can target on the work instead of finding proper methods & typing them."

See, Suppose If I add a Table View to my View Controller, I must have the methods like ..didSelectAtRow..,..CellForRow...,etc.

So, after adding tableView - for managing table view I have to go for finding methods & type them in my .m file.

Suppose, I add tableView. All methods should be added to my .m file as given below.

<pre>

pragma mark Table view methods

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; }

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 0; }

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } return cell; } // Override to support row selection in the table view. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Navigation logic may go here -- for example, create and push another view controller. // AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil]; // [self.navigationController pushViewController:anotherViewController animated:YES]; // [anotherViewController release]; }

// Override to support conditional editing of the table view. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the specified item to be editable. return YES; }

// Override to support editing the table view. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

if (editingStyle == UITableViewCellEditingStyleDelete) {
    // Delete the row from the data source.
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}   
else if (editingStyle == UITableViewCellEditingStyleInsert) {
    // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}   

}

// Override to support rearranging the table view. - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { }

// Override to support conditional rearranging of the table view. - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the item to be re-orderable. return YES; }

3

3 Answers

2
votes

I provided the answer to the question you mentioned - it definitely is in the Apple documentation (although as you say, not in the sample file). Remember the method name is

tableview:didSelectRowAtIndexPath

if you miss off the "tableview:" bit at the beginning and just search for

didSelectRowAtIndexPath

you won't find it in the documentation so easily.

If you look in the documentation that comes with XCode, you will see, for example, all methods that you can implement for the UITableview Delegate, including the one I posted to your previous answer. Just type "UITableview" into XCode help, and then select "UITableview delegate". It will then display all the methods available for you to call, and you can even just copy and paste them straight into your code.

I don't know if anyone's already done this and made the "template" classes you ask about available, but it should be very easy for you to do this yourself if you want.

Hope that helps

1
votes

Sure; implementors of classes are free to implement any number of methods as a part of a class's internal implementation.

But that doesn't mean that you should use them.

You can use the Objective-C runtime's API for figuring out all the methods and classes, including those that aren't publicly declared.

But don't bother.

Specifically, if a method is not declared in the provided header files and is not documented in the documentation, don't use it. Using such a method will lead to fragility and maintenance headaches; your app may likely break at the next software update.

On the iPhone, your are expressly directed not to use private interfaces and your app will run the risk of rejection if you do so.

But I don't think that is what you are really asking. You mention:

Say for example. UITableView methods includes

didSelectRowAtIndexPath cellForRowAtIndex Path numberOfSectionsInTableView titleForHeaderInSection

However, UITableView does not declare any of those methods. Instead, it declares:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

Or, succinctly, tableView:didSelectRowAtIndexPath:, etc...

1
votes

The methods you describe are in the documentation. They're in UITableViewDelegate and UITableViewDataSource, which are described at the top of the UITableView documentation. You can easily copy and paste the method definitions you need from the documentation. You can also find the protocol definition in the headers easily by using "File>Open Quickly..." and typing in the name of the protocol ("UITableViewDelegate" for instance). They are often written in the headers to make it easy to copy and paste what you need most often.

This is sometimes a small hassle in Cocoa, because Xcode doesn't auto-complete method signatures. It would save a little trouble if it did. But the solution is not to implement every delegate method that exists (as @bbum pointed out earlier). In the vast majority of cases, only a small fraction of the possible delegate methods are ever implemented. So automatically populating them all would cause much more work than it saved.