Why doe my UITableView only show two rows of each section?
Posted
by
Mike Owens
on Stack Overflow
See other posts from Stack Overflow
or by Mike Owens
Published on 2010-12-31T00:46:43Z
Indexed on
2010/12/31
0:53 UTC
Read the original article
Hit count: 269
I have a UITableView and when I build it only two rows will be displayed. Each section has more than two cells to be displayed, I am confused since they are all done the same?`#import #import "Store.h"
import "VideoViewController.h"
@implementation Store @synthesize listData;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [self createTableData]; [super viewDidLoad]; }
(void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use. }
(void)viewDidUnload { //self.listData = nil; //[super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; }
pragma mark -
pragma mark Table View Data Source Methods
// Customize the number of sections in the table view. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return [videoSections count]; }
//Get number of rows -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.listData count]; }
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *StoreTableIdentifier = @"StoreTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:StoreTableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:StoreTableIdentifier] autorelease];
}
cell.textLabel.text = [[[listData objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]
objectForKey:@"name"];
//Change font and color of tableView
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.font=[UIFont fontWithName:@"Georgia" size:16.0];
cell.textLabel.textColor = [UIColor brownColor];
return cell;
}
-(NSString *)tableView: (UITableView *)tableView titleForHeaderInSection: (NSInteger) section { return [videoSections objectAtIndex:section]; }
-(void)tableView: (UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath { VideoViewController *videoViewController = [[VideoViewController alloc] initWithNibName: @"VideoViewController" bundle:nil];
videoViewController.detailURL = [[NSURL alloc] initWithString:
[[[listData objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]
objectForKey:@"url"]];
videoViewController.title = [[[listData objectAtIndex:indexPath.section]
objectAtIndex:indexPath.row] objectForKey:@"name"];
[self.navigationController pushViewController:videoViewController animated:YES];
[videoViewController release];
}
pragma mark Table View Methods
//Data in table cell -(void) createTableData { NSMutableArray *beginningVideos; NSMutableArray *intermediateVideos;
videoSections = [[NSMutableArray alloc] initWithObjects:
@"Beginning Videos", @"Intermediate Videos", nil];
beginningVideos = [[NSMutableArray alloc] init];
intermediateVideos = [[NSMutableArray alloc] init];
[beginningVideos addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:@"Shirts", @"name",
@"http://www.andalee.com/iPhoneVideos/testMovie.m4v", @"url", nil]];
[beginningVideos addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:@"Posters", @"name",
@"http://devimages.apple.com/iphone/samples/bipbopall.html", @"url", nil]];
[beginningVideos addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:@"Stickers",@"name",
@"http://www.andalee.com/iPhoneVideos/mov.MOV",@"url",nil]];
[beginningVideos addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:@"Egyptian",@"name",
@"http://www.andalee.com/iPhoneVideos/2ndMovie.MOV",@"url",nil]];
[intermediateVideos addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:@"Drum Solo", @"name",
@"http://www.andalee.com", @"url", nil]];
[intermediateVideos addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:@"Veil", @"name",
@"http://www.andalee.com", @"url", nil]];
[intermediateVideos addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:@"Three Quarter Shimmy",@"name",
@"http://www.andalee.com",
@"url",nil]];
listData = [[NSMutableArray alloc] initWithObjects:beginningVideos, intermediateVideos, nil];
[beginningVideos release];
[intermediateVideos release];
}
- (void)dealloc { [listData release]; [videoSections release]; [super dealloc]; }
@end `
© Stack Overflow or respective owner