2014-02-10 108 views
-1

我有以下陣列其中之一是爲足球比賽和一個是針對部分:鴻溝行

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]]; 

我如何可以選擇哪些比賽應該在什麼板塊?

現在所有的比賽在每個段一倍這樣的: enter image description here

+0

添加到問題的規定(這行* *應在其中一節),並顯示您正在使用的代碼。 – Wain

回答

0

而是對比賽你應該在你的tableView數據源創建兩個數組的

[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]]; 

,然後加載相應的陣列創建單個陣列方法

- (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; 
} 
+0

然後我用我的cellForRowAtIndexPath做什麼: 因爲我需要在那裏使用2個數組? – user3258468

+0

是的,您可以檢查cellForRowAtUndexPath中的部分:.看到我編輯的答案 –

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];