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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-24-2009, 05:30 PM   #1 (permalink)
iPhone Developer
 
Join Date: Aug 2009
Posts: 64
Post use local declaration of UITableView and populate data

hi all
i currently have a view (programmatically, not ib) and i want to add a UITableView. then load some simple data from a NSArray. i can create and add the UITableView to the current view by using:

Code:
[self addSubview:myTableView];
however i do not know where i should add code to populate my data.
any help is appreciated
__________________
If I helped you in any way, please help me by checking out my apps:

iPower Your Device --- Charge Up your device!

(FREE)


losingSkillz is offline   Reply With Quote
Old 12-25-2009, 06:23 AM   #2 (permalink)
simpsonaty Apps
 
simpsonaty's Avatar
 
Join Date: Dec 2009
Location: Australia
Posts: 93
Default

It would be much easier to use IB to create your UITableView and populate the array. You can start populating the NSArray in the - (void)viewDidLoad method. Don't forget to add the array in the .h header file.

Code:
- (void)viewDidLoad {
myArray = [[NSArray alloc] initWithObjects:@"1", @"2", @"3", nil];
[super viewDidLoad];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}

// Set up the cell...
cell.text = [myArray objectAtIndex:indexPath.row];
return cell;
}
__________________
http://simpsonatyapps.com
... yep, that's our site.
simpsonaty is offline   Reply With Quote
Old 12-26-2009, 09:45 AM   #3 (permalink)
iPhone Developer
 
Join Date: Aug 2009
Posts: 64
Post

Quote:
Originally Posted by simpsonaty View Post
It would be much easier to use IB to create your UITableView and populate the array. You can start populating the NSArray in the - (void)viewDidLoad method. Don't forget to add the array in the .h header file.

Code:
- (void)viewDidLoad {
myArray = [[NSArray alloc] initWithObjects:@"1", @"2", @"3", nil];
[super viewDidLoad];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}

// Set up the cell...
cell.text = [myArray objectAtIndex:indexPath.row];
return cell;
}

Thank you for the answer. I have tried using ib and i got it working. however, the [self.tableView reloadData] doesn't seem to work. i know that my array is not nil and it changed before i called [self.tableView reloadData].

also i have added a toolbar to the bottom of the screen but now my tableview is blocked by the toolbar. is there anyway to change the frame size of my tableview? i have tried self.tableView.frame = myNewFrame;
Happy Holidays!
__________________
If I helped you in any way, please help me by checking out my apps:

iPower Your Device --- Charge Up your device!

(FREE)


losingSkillz is offline   Reply With Quote
Reply

Bookmarks

Tags
addsubview, nsarray, uitableview, uiview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 244
13 members and 231 guests
ADY, AragornSG, CKAmike, Dani77, Duncan C, HDshot, HemiMG, Promo Dispenser, Punkjumper, Rudy, sacha1996, sneaky, spiderguy84
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,231
Posts: 380,768
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:19 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0