我有一个小的社交网络,我试图将评级代码实现到表格视图中,它用星来判断评级......问题是第二部分显示来自第一个表格部分的评级
图片:
所以你可以看到它在一些表格视图单元格中显示评级,只是最后一对,为什么要这样做?
绘图代码:
-(void)drawRect:(CGRect)rect
{
if(_shouldDrawRating)
{
self.desc_image.layer.cornerRadius = 8;
self.desc_image.clipsToBounds = YES;
_rating = [[UIStarRateView alloc]initWithFrame:CGRectMake(220,35,70,15)];
[_rating setMaxStars:5];
[_rating setFullImage:[UIImage imageNamed:@"StarFull.png"]];
[_rating setHalfImage:[UIImage imageNamed:@"StarHalf.png"]];
[_rating setEmptyImage:[UIImage imageNamed:@"StarEmpty.png"]];
[_rating setRate:_postRating];
[self addSubview:_rating];
}
}
单元格渲染代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
Regular_Cell *cell;
// Configure the cell...
if(indexPath.section == 0)
{
if(indexPath.row < NUMBER_OF_DYNAMIC_ROWS_RECENT)
{
cell = [tableView dequeueReusableCellWithIdentifier:@"default"];
if(cell == nil)
{
cell = [[Regular_Cell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"default"];
}
NSDictionary *dict = self.recentArray[indexPath.row];
[cell setShouldDrawRating:YES];
[cell.title_label setText:dict[@"title"]];;
[cell.author_label setText:[NSString stringWithFormat:@"Author: %@",dict[@"author"]]];
[cell.views_label setText:[NSString stringWithFormat:@"Views: %@",dict[@"views"]]];
[cell setPoll_idFromString:[NSString stringWithFormat:@"%@",dict[@"id"]]];
//options for image view
cell.desc_image.contentMode = UIViewContentModeScaleAspectFill;
NSURL *imageURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@",dict[@"imageURL"]]];
[cell.desc_image setImageURL:imageURL];
[cell setPostRating:indexPath.row+0.5];
}
else if(indexPath.row == NUMBER_OF_DYNAMIC_ROWS_RECENT)
{
cell = [tableView dequeueReusableCellWithIdentifier:@"See More"];
if(cell == nil)
{
cell = [[Regular_Cell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"See More"];
}
}
else
{
cell = nil;
}
NSLog(@"%@",indexPath);
}
if(indexPath.section == 1)
{
if(indexPath.row < NUMBER_OF_DYNAMIC_ROWS_TOP)
{
cell = [tableView dequeueReusableCellWithIdentifier:@"default"];
if(cell == nil)
{
cell = [[Regular_Cell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"default"];
}
NSDictionary *dict = self.topViewedArray[indexPath.row];
[cell.title_label setText:dict[@"title"]];
[cell.author_label setText:[NSString stringWithFormat:@"Author: %@",dict[@"author"]]];
[cell.views_label setText:[NSString stringWithFormat:@"Views: %@",dict[@"views"]]];
[cell setPoll_idFromString:[NSString stringWithFormat:@"%@",dict[@"id"]]];
//options for image view
cell.desc_image.contentMode = UIViewContentModeScaleAspectFill;
NSURL *imageURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@",dict[@"imageURL"]]];
[cell.desc_image setImageURL:imageURL];
}
else if(indexPath.row == NUMBER_OF_DYNAMIC_ROWS_TOP)
{
cell = [tableView dequeueReusableCellWithIdentifier:@"See More"];
if(cell == nil)
{
cell = [[Regular_Cell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"See More"];
}
}
else
{
cell = nil;
}
NSLog(@"%@",indexPath);
}
return cell;
}