开发者

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];
//    开发者_JS百科[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]; 


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!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜