表视图中心单元格总是像拾取器一样突出显示。如果我选择中心单元格,则返回该值。如果我在时间中心点滚动表必须突出显示值只会更改(如选择器操作)如何执行此操作?此任务的任何示例代码。提前谢谢。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
UILabel *modelLabel;
UIButton *modelButton;
modelButton = [UIButton buttonWithType:UIButtonTypeCustom];
modelButton.frame = CGRectMake(0.0, 0.0, LABEL_WIDTH, LABEL_HEIGHT);
modelButton.tag = indexPath.row+100;
[modelButton addTarget:nil action:@selector(modelButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[[cell contentView] addSubview:modelButton];
modelLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, LABEL_WIDTH, LABEL_HEIGHT)];
modelLabel.text = [NSString stringWithFormat:@"%@", [[modelArray objectAtIndex:indexPath.row] valueForKey:@"Model"]];
modelLabel.tag = indexPath.row+1000;
modelLabel.backgroundColor = [UIColor clearColor];
modelLabel.textColor = [UIColor grayColor];
modelLabel.alpha = 0.5;
modelLabel.textAlignment = UITextAlignmentCenter;
modelLabel.font = EUROSLITE_FONT(14);
[[cell contentView] addSubview:modelLabel];
}
return cell;
}
行数是700,800,就像这样。
答案 0 :(得分:1)
UITableView
扩展UIScrollView
。所以你可以实现以下委托:
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
在那里,您可以检查scrollView.contentOffset
并将相应的单元格设置为突出显示。请注意,这不是中心单元格。您需要在(int)(scrollView.frame.size.height/2)-(int)(cell.frame.size.height/2)
上添加scrollView.contentOffset.y
。
示例(请取消突出显示所有其他单元格):
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[[tableView visibleCells] makeObjectsPerformSelector:@selector(setHighlighted:) withObject:[NSNumber numberWithBool:NO]];
CGPoint center = CGPointMake(0, scrollView.contentOffset.y+(int)(scrollView.frame.size.height/2));
NSIndexPath *cellIndexPath = [tableView indexPathForRowAtPoint:center];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:cellIndexPath];
[cell setHighlighted:YES];
}