开发者

UITableView background doesn't appear until tableview is touched -- also glitchy

I have a UITableView 开发者_运维技巧in my app. Everything works fine until I put this code below in the

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

//this is the code that causes the problem.

  UIView *blackBGView = [[UIView alloc] init]; 
  blackBGView.backgroundColor = [UIColor blackColor];
  cell.backgroundView = blackBGView;

The problem is that the background doesn't appear until you click the uitableview anywhere. Then after that it works only some of the time. The background view is just really glitchy.

What am I doing wrong?


Define in blackBGView your header, then call the following code in your viewDidLoad:

blackBGView = [[UIView alloc] init]; 
blackBGView.backgroundColor = [UIColor blackColor];

Then in cellForRowAtIndexPath: you can call:

cell.backgroundView = blackBGView;

However, I am not sure why you are adding a UIView to your cell, when you can just call:

- (void)tableView: (UITableView*)tableView 
  willDisplayCell: (UITableViewCell*)cell 
forRowAtIndexPath: (NSIndexPath*)indexPath
{
    cell.backgroundColor = [UIColor blackColor];
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜