2010-12-31 4 views
0

저는 UITableView를 가지고 있고 그것을 만들 때 두 개의 행만 표시됩니다. 각 섹션에는 표시 할 셀이 3 개 이상 있습니다. 모두 동일하게 처리되었으므로 혼란 스럽습니다.왜 내 UITableView는 각 섹션에 2 행만 표시합니까?

#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 
+0

당신 거 수정해야 쉽게 읽을 수 있도록 여기에 서식을 지정하십시오. – WrightsCS

답변

3

꽤 어려운이 :와

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [self.listData count]; 
} 

:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [[self.listData objectAtIndex:section] count]; 
} 
+0

감사합니다. 나는 몇 주 동안 이것에 대한 나의 작은 두뇌를 고심했다! –

1

는 섹션 당 행 수에 대해 하나 개의 값을 사용하고있는 것 같습니다 :

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [self.listData count]; 
} 

, 각 영역은 같은 수의 행이 있습니까? 그렇지 않은 경우 section을 사용하여 올바른 번호를 가져야합니다.

해당 섹션에 대해 표시 할 행 수를 결정하는이 메소드 (귀하의 경우 [self.listData count])에서 반환되는 값입니다.

좀 더 코드를 분석 싶지만이 교체 :) ... 자세히

관련 문제