2012-04-25 43 views
2

我有一組評論,我輸出到分組表中。當我將sections方法發送到[array count]時,我希望每個review都在它自己的tableview節中,它只是爲數組中的許多項重複相同的組。任何想法,我怎麼能做到這一點?我希望這是有道理的。由於UITableView分組顯示每個部分中的新信息

- 編輯 -

加什麼,我想達到的圖片和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 2012-04-25 09:35:55

+1

作爲一個旁註...你可以用'cell.myImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@「rating _%@。png」,[object objectForKey:@「rating」 ]]];' – Alladinian 2012-04-25 11:01:29

回答

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 2012-04-25 14:06:54

3

只需返回1爲numberOfRowsFor每個部分。 添加我定的代碼在你的代碼

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

這意味着每節只有1個單元格或行。我希望這是你想要達到的目標。 (每個審查現在有它自己的部分)

+0

這意味着每個部分只有1個單元格或行。我希望這是你想要達到的目標。 (每個評論現在都有它自己的部分) – 2012-04-25 10:48:55

相關問題