作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 DLStarRating用于显示评级。它工作完美,但是当我在 tableview 单元格中使用它时,滚动时卡住问题开始。我想在 UITableview 中显示评级星星分数例如:- 3.2 ,1.9,2,4.6 等评级。
UITableViewCell *cell=nil;
if(cell==nil)
{
[tableView registerNib:[UINib nibWithNibName:@"TableViewCell" bundle:nil] forCellReuseIdentifier:@"CellID"];
cell = [tableView dequeueReusableCellWithIdentifier:@"CellID"];
cell.selectionStyle = UITableViewCellEditingStyleNone;
}
UILabel *LabelTitle= (UILabel*)[cell viewWithTag:1];
LabelTitle.text=[[ArrayData objectAtIndex:indexPath.row] objectForKey:@"name"];
UILabel *LabelAddress= (UILabel*)[cell viewWithTag:100];
LabelAddress.text=[[ArrayData objectAtIndex:indexPath.row] objectForKey:@"address"];
UIImageView *imgView = (UIImageView*)[cell viewWithTag:200];
[imgView setImageWithURL:[NSURL URLWithString:[[ArrayData objectAtIndex:indexPath.row] objectForKey:@"icon"]] placeholderImage:[UIImage imageNamed:@"loading.png"]];
DLStarRatingControl *customNumberOfStars = [[DLStarRatingControl alloc] initWithFrame:CGRectMake(20, 140, 140, 30) andStars:5 isFractional:YES];
customNumberOfStars.delegate = self;
customNumberOfStars.backgroundColor = [UIColor groupTableViewBackgroundColor];
customNumberOfStars.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
customNumberOfStars.rating = [[ArrayData objectAtIndex:indexPath.row] floatValue];
[cell addSubview:customNumberOfStars];
return cell;
最佳答案
你这样做是不对的。
您应该按照以下步骤操作。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * CellIdentifier = @"CellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell==nil)
{
cell = [[NSBundle mainBundle] loadNibNamed:@"TableViewCell" owner:nil options:nil][0];
cell.selectionStyle = UITableViewCellEditingStyleNone;
DLStarRatingControl *customNumberOfStars = [[DLStarRatingControl alloc] initWithFrame:CGRectMake(20, 140, 140, 30) andStars:5 isFractional:YES];
customNumberOfStars.tag = 1001;
customNumberOfStars.delegate = self;
customNumberOfStars.backgroundColor = [UIColor groupTableViewBackgroundColor];
customNumberOfStars.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
[cell addSubview:customNumberOfStars];
}
UILabel *LabelTitle= (UILabel*)[cell viewWithTag:1];
LabelTitle.text=[[ArrayData objectAtIndex:indexPath.row] objectForKey:@"name"];
UILabel *LabelAddress= (UILabel*)[cell viewWithTag:100];
LabelAddress.text=[[ArrayData objectAtIndex:indexPath.row] objectForKey:@"address"];
UIImageView *imgView = (UIImageView*)[cell viewWithTag:200];
[imgView setImageWithURL:[NSURL URLWithString:[[ArrayData objectAtIndex:indexPath.row] objectForKey:@"icon"]] placeholderImage:[UIImage imageNamed:@"loading.png"]];
DLStarRatingControl *customNumberOfStars = (customNumberOfStars *)[cell viewWithTag:1001];
customNumberOfStars.rating = [[ArrayData objectAtIndex:indexPath.row] floatValue];
return cell;
}
[UITableView registerNib: forCellReuseIdentifier:]
因为您需要将评级控件添加为 subview 。您每次都添加它
cellForRowAtIndexPath
方法调用,现在它只会在创建新单元格时添加。
关于ios - 在 iOS 中使用评级星 (DLStarRating) 时在滚动时卡住 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24185968/
我正在使用 DLStarRating用于显示评级。它工作完美,但是当我在 tableview 单元格中使用它时,滚动时卡住问题开始。我想在 UITableview 中显示评级星星分数例如:- 3.2
我是一名优秀的程序员,十分优秀!