Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 12-19-2008, 10:36 AM   #2 (permalink)
exorcyze
Registered Member
 
Join Date: Dec 2008
Posts: 495
exorcyze is on a distinguished road
Default

Here's a tutorial on hooking up an array to a table view. I used it as a basis for learning and found it very helpful:
iPhone Programming Tutorial - Populating UITableView With An NSArray | iCodeBlog

I'm not aware offhand of being able to just programmatically say something like:
UITableView *x = [[UITableView alloc] init];
[x setData:myArrayData];

In a nutshell, create a new class that derives from UITableViewController. There are a couple of important methods : numberOfRowsInSection and cellForRowAtIndexPath.

numberOfRowsInSection needs to have a number returned to tell how many rows there are. This would typically be the number of items in your array. That array could be internal or inside your delegate. Here's an example of using the count from a data array inside the delegate:
Code:
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
    return [delgate.myDataArray count];
}
The other one is what actually requests ( on a cell by cell basis ) the data that should go in that cell. Using the same example of having a data array inside your delegate, it would look something like this:
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    // lines for setting up the cell resource itself
    // ....
    // now set the cell data
    MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
    [cell setText:[delegate.myDataArray objectAtIndex:indexPath.row]];

    return cell;
}
Hopefully that helps!
exorcyze is offline   Reply With Quote
 

» Advertisements
» Online Users: 413
20 members and 393 guests
7twenty7, alexeir, amit.mangal, chemistry, dbramhall, demas, elhanche, freewind, HarrysLad, Hercule, iphonedevshani, jamiekeniston, jeroenkeij, Johnsyfared, jPuzzle, logan, milanalina, samball, smashing, Tusarari
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,605
Threads: 94,084
Posts: 402,783
Top Poster: BrianSlick (7,990)
Welcome to our newest member, champa812
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:13 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.