2012-09-30 4 views
0

나는 JSON으로 채워지는 tableview을 가지고 있지만, 그 값은 두 배입니다. 나는 2 개의 물체만을 가지고 있지만, 그것은 4를 tableview에 넣고 있습니다. 누군가 내가 잘못하고있는 것을 말해 줄 수 있습니까? 왜 제가 2 개 밖에 없을 때 4 개의 물건을 열거하고 있습니까? 나는 카운트와 데이터 모델을 체크했고 그것들은 모두 2 개의 아이템만을 보여준다.TableView에서 더 많은 셀

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
rootList =[[GlobalData sharedData].mRootBeers getRootBeers]; 
NSLog(@"RootList: %@", rootList); 
// Return the number of sections. 
NSLog(@"RootList count: %i", rootList.count); 
return rootList.count; 
} 

변화를이에 ...이 이유라고 생각

// 
// RootBeerTableViewController.m 
// BaseApp 
// 
// Created by Blaine Anderson on 9/27/12. 
// Copyright (c) 2012 UIEvolution, Inc. All rights reserved. 
// 

#import "RootBeerTableViewController.h" 
#import "GlobalData.h" 

@interface RootBeerTableViewController() 



@end 

@implementation RootBeerTableViewController 

@synthesize rootList; 

- (id)initWithStyle:(UITableViewStyle)style 
{ 
    self = [super initWithStyle:style]; 
    if (self) { 

    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    UITableView *tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain]; 

    tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth; 

    tableView.delegate = self; 

    tableView.dataSource = self; 

    [tableView reloadData]; 



    self.view = tableView; 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

#pragma mark - Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    rootList =[[GlobalData sharedData].mRootBeers getRootBeers]; 
    NSLog(@"RootList: %@", rootList); 
    // Return the number of sections. 
    NSLog(@"RootList count: %i", rootList.count); 
    return rootList.count; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
     // Return the number of sections. 
    NSLog(@"RootList row count: %i", rootList.count); 
    return rootList.count; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    rootList =[[GlobalData sharedData].mRootBeers rootBeerList]; 
    NSLog(@"RootList Cell: %@", rootList); 
    RootBeers* mRootBeer = [rootList objectAtIndex:indexPath.row]; 


    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if(cell == nil){ 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"]; 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    } 
    NSLog(@"Cell Name: %@", mRootBeer.name); 
     // Configure the cell... 
    cell.textLabel.text = mRootBeer.name; 
    cell.detailTextLabel.text = mRootBeer.brewer; 



    return cell; 
} 

/* 
// Override to support conditional editing of the table view. 
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Return NO if you do not want the specified item to be editable. 
    return YES; 
} 
*/ 

/* 
// Override to support editing the table view. 
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     // Delete the row from the data source 
     [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    } 
    else if (editingStyle == UITableViewCellEditingStyleInsert) { 
     // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view 
    } 
} 
*/ 

/* 
// Override to support rearranging the table view. 
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath 
{ 
} 
*/ 

/* 
// Override to support conditional rearranging of the table view. 
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Return NO if you do not want the item to be re-orderable. 
    return YES; 
} 
*/ 

#pragma mark - Table view delegate 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    [[GlobalData sharedData].mViewManager pushView:DETAILVIEW animated:YES]; 



} 

@end 

답변

1

:

여기 내 코드입니다.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
return 1; 
} 

각 개체에 대한 섹션을 rootList에 추가 한 다음 각 섹션에 모든 루트 목록을 추가합니다. 따라서 하나의 섹션 만 반환하는 것이 가장 쉽습니다.

+0

Perfect! 고맙습니다! 문제를 해결했습니다! – BlackHatSamurai

관련 문제