我想显示来自两个数组的数据,第一部分是topScoreArray,tableview的第二部分是dataArray。我将tableview划分为两个部分的代码运行良好,但它始终只显示两个部分的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];
}
我的tableview就像这样
- (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;
}