为 EKEventEditViewController 设置背景颜色/图像

发布于 2024-12-09 19:08:16 字数 1609 浏览 0 评论 0原文

以下是我添加日历事件的代码。我想发送 EKEventEditViewController 的背景图像。我找到了这段代码

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

使用此代码我能够为 EKEventViewController 设置背景图像,但它不适用于 EKEventEditViewController。非常感谢任何帮助。提前致谢。

     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]; 

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]; 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

皓月长歌 2024-12-16 19:08:16

这件事让我抓狂了一段时间,但我终于明白了。

诀窍是以某种方式访问​​ EKEventEditViewController 内的表视图,并且似乎只有一种(已记录的)方法可以做到这一点:

首先,设置呈现 EKEventEditViewController 的视图控制器(或任何您想要的)想要负责自定义)作为 UINavigationControllerDelegate

@interface YourViewController : UIViewController <UINavigationControllerDelegate>

其次,将视图控制器设置为 EKEventEditViewController 的委托:

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

第三,在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;
    }
}

此示例会将 EKEventEditViewController 的表视图背景更改为蓝色,但现在您可以访问实际的导航控制器和内部的表视图,您可以做任何您想做的事情!

注意:我尚未向 Apple 提交此代码,但我没有使用任何未记录的内容,因此我不知道什么会导致问题。

享受!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文