我有以下数组,其中一个用于足球比赛,一个用于各个部分:
sectionsArray = [[NSMutableArray alloc] init];
[sectionsArray addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Barclays Premier League",@"league", @"england.png",@"img", nil]];
[sectionsArray addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Primera Division",@"league", @"spain.png",@"img", nil]];
array1 = [[NSMutableArray alloc] init];
[array1 addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Tottenham",@"hometeam", @"Everton",@"awayteam", @"1", @"homescore", @"0", @"awayscore", nil]];
[array1 addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Manchester Utd",@"hometeam", @"Fulham",@"awayteam", @"2", @"homescore", @"2", @"awayscore", nil]];
我如何选择哪些匹配应该在哪些部分?
现在所有匹配在每个部分加倍,如下所示:
答案 0 :(得分:0)
不应为匹配创建单个数组,而应创建两个数组
[arrayBarclay addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Tottenham",@"hometeam", @"Everton",@"awayteam", @"1", @"homescore", @"0", @"awayscore", nil]];
[arraySpanish addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Team1",@"hometeam", @"Team2",@"awayteam", @"2", @"homescore", @"2", @"awayscore", nil]];
然后在tableView数据源方法中加载适当的数组
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(section==0)
{
return [arrayBarclay count];
}
return [arraySpanish count];
}
在cellForRowAtIndexPath
中- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellidentifier= @"cellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellidentifier];
if (cell==Nil)
{
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellidentifier] autorelease];
}
if(indexPath.section==0
{
cell.detailTextLabel.text= [arrayBarclay objectAtIndex:indexPath.row];
}
else
{
cell.detailTextLabel.text= [arraySpanish objectAtIndex:indexPath.row];
}
return cell;
}
答案 1 :(得分:0)
sectionsArray = [[NSMutableArray alloc] init];
sectionOneRows = [[NSMutableArray alloc] init];
[sectionOneRows addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Barclays Premier League",@"league", @"england.png",@"img", nil]];
[sectionOneRows addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Primera Division",@"league", @"spain.png",@"img", nil]];
sectionTwoRows = [[NSMutableArray alloc] init];
[sectionTwoRows addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Tottenham",@"hometeam", @"Everton",@"awayteam", @"1", @"homescore", @"0", @"awayscore", nil]];
[sectionTwoRows addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Manchester Utd",@"hometeam", @"Fulham",@"awayteam", @"2", @"homescore", @"2", @"awayscore", nil]];
[sectionsArray addObject:sectionOneRows];
[sectionsArray addObject:sectionTwoRows];
在cellForRowAtIndexPath方法中,
NSDictionary *dict = [[sectionArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];