Sunday, 11 August 2013

UITableViewCell background image disappears after scrolling

UITableViewCell background image disappears after scrolling

I am initializing a EventEditViewController to add a new event with the
following code:
-
(void)presentEventEditViewControllerWithEventStore:(EKEventStore*)eventStore
{
EKEventEditViewController* vc = [[EKEventEditViewController alloc] init];
vc.eventStore = eventStore;
vc.delegate = self; // Probably self
EKEvent* event = [EKEvent eventWithEventStore:eventStore];
event.title = @"";
event.startDate = [NSDate date];
event.endDate = [NSDate date];
event.URL = [NSURL URLWithString:@""];
event.notes = @"";
event.allDay = NO;
vc.event = event;
vc.editViewDelegate = self;
[self presentViewController:vc animated:NO completion:nil];
}
- (void)navigationController:(UINavigationController
*)navigationController willShowViewController:(UIViewController
*)viewController animated:(BOOL)animated {
UITableView *tableView = ((UITableViewController
*)viewController).tableView;
if ([viewController isKindOfClass:[UITableViewController class]]) {
//((UITableViewController
*)viewController).tableView.backgroundColor = [UIColor
clearColor];
for (NSInteger j = 0; j < [tableView numberOfSections]; ++j)
{
for (NSInteger i = 0; i < [tableView numberOfRowsInSection:j];
++i)
{
UITableViewCell *cell = [tableView
cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i
inSection:j]];
cell.backgroundView = [[UIImageView alloc]
initWithImage:[UIImage
imageNamed:@"Background-1.png"]];
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.backgroundColor = [UIColor clearColor];
}
}
}
}
The UITableView appears as it should, but when I start scrolling until a
UITableViewCell is not on the iPhone's screen anymore and then scroll
back, the TableViewCell forgets its image and turns into a standard
UITableViewCell (without any background image or customization).
Screenshot before scrolling: http://postimg.org/image/vzlj3t5o9/)
Screenshot after scrolling: (http://postimg.org/image/c30836v2v/)
How can I resolve this issue?
Thank you in advance!

No comments:

Post a Comment