开发者

Change image or style of specific UITableViewCell

Is there any way that I can get a specific cell to change its style or background image while scrolling the table view?

I want to change the image of a cell which is on top of the visible cells. But only its image is going to be changed the others will stay same, until after scrolling the others com开发者_StackOverflow中文版e to top of the cells which are shown on the screen. Then the top one's image is going to change this time.


You need to implement scrollViewDidScroll: method of UIScrollViewDelegate in your controller then use visibleCells property of UITableView to get the visible cells of the table.

Something like the following code should work

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
 UITableView* tableView;
 NSArray* visibleCells;
 BOOL first;

 tableView = (UITableView*)scrollView;
 visibleCells = tableView.visibleCells;
 first = YES;
 for (UITableViewCell* cell in visibleCells) {
  if (first) {
   //customize the top cell
   first = NO;
  }else {
   //customize the other visible cells
  }
 }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜