Ios 将行分成不同的部分
我有以下阵列,其中一个用于足球比赛,另一个用于分区:Ios 将行分成不同的部分,ios,iphone,objective-c,uitableview,Ios,Iphone,Objective C,Uitableview,我有以下阵列,其中一个用于足球比赛,另一个用于分区: sectionsArray = [[NSMutableArray alloc] init]; [sectionsArray addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Barclays Premier League",@"league", @"england.png",@"img", nil]]; [sectionsArray addObject:[[NSMu
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]];
我如何选择哪一个匹配应该在哪一部分中
现在,每个部分的所有匹配项都加倍,如下所示:
与其为匹配项创建单个数组,不如创建两个数组的
[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;
}
在cellForRowAtIndexPath方法中
NSDictionary *dict = [[sectionArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
将要求添加到问题中(哪些行应位于哪个节中),并显示您当前使用的代码。然后我该如何处理我的cellForRowAtIndexPath:因为我需要在其中使用2个数组?是的,您可以检查cellForRowAtUndexPath:中的节。见我编辑的答案
NSDictionary *dict = [[sectionArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];