2012-04-25 1 views
2

그룹화 된 테이블로 출력하고있는 리뷰 배열이 있습니다. 내가 section methods를 [array count]로 보냈을 때 각 리뷰가 그것의 자신의 tableview 섹션에 있기를 원한다. 단지 많은 아이템이 배열에있는 동안 같은 그룹을 반복한다. 어떤 생각이라도 어떻게 할 수 있니? 나는 그것이 의미가 있기를 바랍니다. 감사합니다UITableView는 모든 섹션에 새 정보를 그룹화했습니다.

--EDIT--

추가 내가 무엇을 달성하고자하는의 사진과 cellForRow/제/DidSelectRowMethod의 내가이 당신 때문에 모든

enter image description here

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

    static NSString *CellIdentifier = @"Cell"; 
    CustomCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 
     cell = [[[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 

    } 


    cell.primaryLabel.text = [object objectForKey:@"comment"]; 

    if([[object objectForKey:@"rating"] isEqualToString:@"0"]) 
    { 
     cell.myImageView.image = [UIImage imageNamed:@"rating_0.png"]; 
    } 
    if([[object objectForKey:@"rating"] isEqualToString:@"1"]) { 
     cell.myImageView.image = [UIImage imageNamed:@"rating_1.png"]; 
    } 
    if([[object objectForKey:@"rating"] isEqualToString:@"2"]) 
    { 
     cell.myImageView.image = [UIImage imageNamed:@"rating_2.png"]; 
    } 
    if([[object objectForKey:@"rating"] isEqualToString:@"3"]) 
    { 
     cell.myImageView.image = [UIImage imageNamed:@"rating_3.png"]; 
    } 
    if([[object objectForKey:@"rating"] isEqualToString:@"4"]) 
    { 
     cell.myImageView.image = [UIImage imageNamed:@"rating_4.png"]; 
    } 
    if([[object objectForKey:@"rating"] isEqualToString:@"5"]) 
    { 
     cell.myImageView.image = [UIImage imageNamed:@"rating_5.png"]; 
    } 


    return cell; 

} 


// Override if you need to change the ordering of objects in the table. 
- (PFObject *)objectAtIndex:(NSIndexPath *)indexPath 
{ 
    return [self.objects objectAtIndex:indexPath.row]; 
} 

#pragma mark - Table view delegate 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    PFObject *object = [self.objects objectAtIndex:indexPath.row]; 
    Review *review = [[Review alloc] initWithNibName:@"Review" bundle:nil]; 
    review.Name = [object objectForKey:@"userId"]; 
    NSLog(@"%@",[object objectForKey:@"userId"]); 
    review.rating = [object objectForKey:@"rating"]; 
    review.comments = [object objectForKey:@"comment"]; 

    [self.navigationController pushViewController:review animated:YES]; 

    [review release]; 

} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return [self.objects count]; 
} 
+0

질문을 좀 더 명확하게 게시 할 수 있습니까? – Minakshi

+1

sidenote ... 당신은 모든 if 문을 다음으로 대체 할 수 있습니다 :'cell.myImageView.image = [UIImage imageNamed : [NSString stringWithFormat : @ "rating _ % @. png", [object objectForKey : @ "rating" ]]]; ' – Alladinian

답변

2

의 명확히 희망 모든 리뷰를 별도의 그룹으로 만들려면 배열 인덱스의 행 대신 색인 경로의 섹션을 사용해야합니다 (섹션 당 행이 하나뿐이므로 행은 항상 0입니다) :

// Override if you need to change the ordering of objects in the table. 
- (PFObject *)objectAtIndex:(NSIndexPath *)indexPath 
{ 
    return [self.objects objectAtIndex:indexPath.section]; 
} 
+0

완벽! 감사합니다 – Bradley

3

모든 섹션의 numberOfRowsFor에 대해 1을 반환합니다. 이 모든 섹션은 한 셀 또는 행이 있다는 것을 의미

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
    return 1; 
} 

코드에서 내 주어진 코드를 추가 . 이것이 당신이 달성하기를 바라는 바램입니다. (각 리뷰는 이제 자신 만의 섹션을 갖게됩니다)

+0

이것은 모든 섹션에는 셀 또는 행이 하나만 있음을 의미합니다. 이것이 당신이 달성하기를 바라는 바램입니다. (각 리뷰에는 이제 자신의 섹션이 있습니다) –

관련 문제