2012-01-31 3 views
0

나는 두 섹션으로 설정 한 UITableView을 가지고 있습니다. 아래의 코드는 UITableView 전체에 동일한 셀 텍스트를 표시합니다. 간단히 말해, 제 질문은 섹션을 어떻게 할당합니까 NSArrays?UITableView - UITableView의 오른쪽 섹션에 배열 할당

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    UITableViewCell *cell = [toStartPicker dequeueReusableCellWithIdentifier:@"cell"]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"]; 
    } 
    cell.textLabel.text= [nameJan objectAtIndex:indexPath.row]; 
    cell.detailTextLabel.text= [subTitlesJan objectAtIndex:indexPath.row]; 

    UITableViewCell *cellTwo = [toStartPicker dequeueReusableCellWithIdentifier:@"cellTwo"]; 
    if (cellTwo == nil) { 
     cellTwo = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cellTwo"]; 
    } 
    cellTwo.textLabel.text= [nameFeb objectAtIndex:indexPath.row]; 
    cellTwo.detailTextLabel.text= [subTitlesFeb objectAtIndex:indexPath.row]; 

    return cell; 
} 

답변

1

또한이

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    UITableViewCell *cell = [toStartPicker dequeueReusableCellWithIdentifier:@"cell"]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"]; 
    } 
    if(indexPath.section == 0) 
    { 
     cell.textLabel.text= [nameJan objectAtIndex:indexPath.row]; 
     cell.detailTextLabel.text= [subTitlesJan objectAtIndex:indexPath.row]; 
    } 
    else 
    { 
     cell.textLabel.text= [nameFeb objectAtIndex:indexPath.row]; 
     cell.detailTextLabel.text= [subTitlesFeb objectAtIndex:indexPath.row]; 
    } 
    return cell; 
} 

같은 방법은 다음과 같은 방법이 큰 응답을 다음과 같이

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    // Return the number of sections. 
    return 2; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    // Return the number of rows in the section. 
    if(0 == section) 
    { 
     return [nameJan count]; 
    } 
    else 
    { 
     return [nameFeb count]; 
    } 
} 
+0

감사를 보이는 있는지 확인하세요! – Seb

관련 문제