0

I want to show data from two arrays, topScoreArray on first section and dataArray on second section of tableview. My code for dividing tableview into two sections is working well but it always shows only dataArray on both sections. I don't know what mistake I'm making.

- (void)viewDidLoad
{
    [super viewDidLoad];

    gameSoundsView.hidden = YES;
    // Do any additional setup after loading the view from its nib.
    dataArray = [[NSMutableArray alloc] initWithObjects: @"Terms and conditions",@"Contact us",@"Like us on facebook",nil];
    topScoreArray  =  [[NSMutableArray alloc] init];
    topScoreArray  = [[NSMutableArray alloc] initWithObjects:@"Top Scores",@"Current Score",nil];
}

and my tableview is like this

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 57;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0)
    {
        return topScoreArray.count;
    }
     if (section == 1)
    {
    return  dataArray.count;
    }

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"Custom CellCC";

    customCellCC *cell = (customCellCC *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"customCellCC" owner:self options:nil];
        cell = (customCellCC *)[nib objectAtIndex:0];


    }
    if (indexPath.row %2 ==0) {

        UIView *view =[[UIView alloc]initWithFrame:cell.frame];
        view.backgroundColor=[UIColor greenColor];
        cell.backgroundView =view;
        cell.textLabel.backgroundColor=[UIColor clearColor];
    }
    else
    {

        UIView *view =[[UIView alloc]initWithFrame:cell.frame];
        view.backgroundColor=[UIColor colorWithRed:(255.0/255.0) green:(185.0/255.0) blue:(15.0/255.0) alpha:1.0f];

        cell.backgroundView =view;
        cell.textLabel.backgroundColor=[UIColor clearColor];
    }
    if (indexPath.section == 0) {

         cell.lbltxt.text = [topScoreArray objectAtIndex:indexPath.row];
    }
    if (indexPath.section == 1)
    {

    cell.lbltxt.text = [dataArray objectAtIndex:indexPath.row];
    }

    return cell;
}
4

0 回答 0