Wrox Programmer Forums
|
BOOK: Beginning iOS 4 Application Development
This is the forum to discuss the Wrox book Beginning iOS 4 Application Development by Wei-Meng Lee; ISBN: 978-0-470-91802-9
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning iOS 4 Application Development section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 24th, 2011, 10:10 PM
Registered User
 
Join Date: May 2011
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Ch. 4 -- Split-View Based App, pg. 121

On pg. 121 there's an explanation section (a "How it Works") pertaining to the Split-View App that displays all those Denzel Washington movie posters. Well in the middle of pg. 121 it says:

"The 'tableView: cellForRowAtIndexPath:' method is fired for each item in the mutable array, thereby populating the Table view"

- I don't get it.
HOW is this method "fired" for "each item" in the array? I don't see a loop that's set to run 10 times - not here, not anywhere. I don't see where this method gets called otherwise in other parts of the program - what's the deal? How is this working?

Here's the code:

Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"CellIdentifier";
    
    // Dequeue or create a cell of the appropriate type.
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
									   reuseIdentifier:CellIdentifier] autorelease];
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    
    // Configure the cell.
    //cell.textLabel.text = [NSString stringWithFormat:@"Row %d", indexPath.row];
	
	cell.textLabel.text =[listOfMovies objectAtIndex: indexPath.row];
    return cell;
}
 
Old May 24th, 2011, 11:41 PM
Friend of Wrox
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

The UITableView has built in functionality to draw itself.
The UITableViewDataSource Protocol methods are called by the tableView and provide information about size.

Required protocol methods as implemented in the project:

Code:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView {
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    //return 10;
	return[listOfMovies count];
}
The (numberOfSections * numberOfRows) informs the tableView how many times it will call

Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath…
which provides the information for each cell.
The tableView will automatically load the data when the view is displayed, updates are sometimes handled with -reloadData. Other updates such as insertion and deletion are handled differently. The documentation covers this.

Bob
 
Old May 25th, 2011, 06:37 PM
Registered User
 
Join Date: May 2011
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up thanks!

Got it!

Understood.

Thanks for the straight-forward explanation - much clearer than the Documentation, which I read but which only served to confuse me...

Much Obliged Sir





Similar Threads
Thread Thread Starter Forum Replies Last Post
split string based on Character count ptn77 XSLT 14 September 1st, 2010 12:03 PM
Two tabs split view kuznickic BOOK: WPF Programmer's Reference: Windows Presentation Foundation with C# 2010 and .NET 4 1 August 31st, 2010 09:19 AM
Chapter 4 - Split View-Based App johnoeffinger BOOK: Beginning iPad Application Development 4 May 21st, 2010 05:43 PM
CH 5 pg 160 wadesmart BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 8 November 12th, 2003 11:23 PM
CH 3 pg 76 wadesmart BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 2 October 26th, 2003 08:46 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.