tableview の最初のセクションに topScoreArray を、2 番目のセクションに dataArray の 2 つの配列からデータを表示したいと考えています。tableview を 2 つのセクションに分割するコードはうまく機能していますが、常に両方のセクションに dataArray しか表示されません。私は自分がどんな間違いをしているのかわかりません。
- (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];
}
私のテーブルビューはこのようなものです
- (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;
}