Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set background color/image for EKEventEditViewController

The following is my code for adding a calendar event. I want to sent a background image for EKEventEditViewController. I found this code

UITableView *eventTableView = [[editController.view subviews]objectAtIndex:0]; 

Using this code I was able to set background image for EKEventViewController but its not working for EKEventEditViewController. Any help is greatly appreciated. Thanks in advance.

     EKEventEditViewController *editController = [[EKEventEditViewController alloc] init];
//    UITableView *eventTableView = [[editController.view subviews]objectAtIndex:0];
//    [eventTableView setHidden:YES];

//    [eventTableView setBackgroundColor:[UIColor redColor]];
NSMutableArray *allViewControllers = [NSMutableArray arrayWithArray: editController.viewControllers];
NSLog(@"%i", [allViewControllers count]);
 UITableView *eventTableView = [[[allViewControllers objectAtIndex:0] subviews] objectAtIndex:0];
//    UITableView *eventTableView = [[editController.view subviews]objectAtIndex:0];
//    eventTableView.backgroundColor = [UIColor redColor];
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"honeycomb.png"]];
eventTableView.backgroundColor = background;
//    [background release];
editController.event =  [eventsList objectAtIndex:indexPath.row];
editController.eventStore = self.eventStore;
editController.editViewDelegate = self;
itsSelectedReminder = indexPath.row;
isReminderDeleted = TRUE;
[editController.navigationBar setTintColor:[UIColor colorWithRed:67/255.0 green:114/255.0 blue:18/255.0 alpha:1]]; 
[self presentModalViewController:editController animated:YES];

[editController release];
[tableView deselectRowAtIndexPath:indexPath animated:YES]; 
like image 609
Dilip Rajkumar Avatar asked Oct 13 '11 13:10

Dilip Rajkumar


1 Answers

This one drove me nuts for a while, but I finally figured it out.

The trick is to somehow get access to the table view inside the EKEventEditViewController, and there seems to be only one (documented) way to do that:

First, set the view controller presenting the EKEventEditViewController (or whatever you want to be responsible for the customization) as a UINavigationControllerDelegate:

@interface YourViewController : UIViewController <UINavigationControllerDelegate>

Second, set your view controller to be the EKEventEditViewController's delegate:

EKEventEditViewController *eventEditViewController = [[EKEventEditViewController alloc] init];
eventEditViewController.delegate = yourViewController; // Probably self

Third, implement the following method in the delegate:

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if ([viewController isKindOfClass:[UITableViewController class]]) {
        ((UITableViewController *)viewController).tableView.backgroundColor = [UIColor blueColor];
        ((UITableViewController *)viewController).tableView.backgroundView = nil;
    }
}

This example will change the EKEventEditViewController's table view background to blue, but now that you have access to the actual navigation controller and the table view inside you can do whatever you want!

Note: I have not yet submitted this code to Apple, but I'm not using anything undocumented, so I don't see what would cause an issue.

Enjoy!

like image 53
Justin Michael Avatar answered Oct 28 '22 02:10

Justin Michael