UIDatePicker in iPhone - iphone

I'm struggling with UIDatePicker. I thought I could add it to my current view just as I would an ordinary subview, but it didn't appear. After some searching, I found documentation for putting it in a popover. I followed those instructions and got it to work on the iPad. But popovers don't work on the iPhone. What do I need to do to make it work there? Why can't I simply add it like a regular subview?
Here's my iPad code:
-(void)selectADate: (CGPoint)p
{
UIViewController* popoverContent = [[UIViewController alloc] init]; //ViewController
UIView *popoverView = [[UIView alloc] init]; //view
popoverView.backgroundColor = [UIColor blackColor];
UIDatePicker *datePicker=[[UIDatePicker alloc]init];//Date picker
datePicker.frame=CGRectMake(0,44,320, 216);
datePicker.datePickerMode = UIDatePickerModeDate;
[datePicker setTag:10];
datePicker.date = self.displayedDate;
[datePicker addTarget:self action:#selector(pickerChanged:) forControlEvents:UIControlEventValueChanged];
[popoverView addSubview:datePicker];
popoverContent.view = popoverView;
UIPopoverController * popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
//popoverController.delegate=self;
self.datePopover = popoverController;
[popoverController setPopoverContentSize:CGSizeMake(320, 264) animated:NO];
CGRect popoverLocation = CGRectMake(p.x-160, p.y-200, 320, 216);
[popoverController presentPopoverFromRect:popoverLocation inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];//tempButton.frame where you need you can put that frame//
}
- (void)pickerChanged:(id)sender
{
self.displayedDate = [sender date];
[self showMonthContainingDate:[sender date]];
}
My screen is currently laid out as a sort of calendar page showing a month of days. Each day's sell is a subview. At the top of the screen is a header, which has information on the year, month, etc. When the user taps the header, the date picker appears, and the calendar page displays the month selected that corresponds to the date chosen in the picker with the day highlighted (that day's subview's background has a different color).
I'm not sure why I even need a popover, unless it is just to provide a blank view on which to place the date picker that is in front of the tiled views of my calendar page. But then shouldn't I be able to simply add it as a subview and then call bringSubviewToFront:? I tried that, but it didn't work on the iPad, hence my use of the popover.
I can get it to display if I add it when I add the other subviews, but I want it to display when I tap the heading. Here's my tap code:
- (IBAction)tap:(UITapGestureRecognizer *)sender {
//tap gesture recognizer
//Assume the user tapped on a day cell.
for (UIView *dayCell in self.view.subviews) {
if (CGRectContainsPoint(dayCell.frame, [sender locationInView:self.view])) {
//found the cell that was touched.
//NSLog(#"Found a view containing the touch with coords. %#",NSStringFromCGRect(dayCell.frame));
for (UIView *insideView in dayCell.subviews) {
for (UILabel *dayElement in insideView.subviews) {
//found a subview of the day cell.
if ([dayElement isKindOfClass:[UILabel class]]) {
NSLog(#"Found a subview %#",dayElement.text);
}
}
}
}
if ([dayCell isKindOfClass:[UILabel class]]) {
// This is the heading label.
UILabel * headingLabel = (UILabel *) dayCell;
if (CGRectContainsPoint(headingLabel.frame, [sender locationInView:self.view])) {
NSLog(#"The heading was tapped");
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
//iPhone code goes here
[self iphoneSelectADate:[sender locationInView:self.view]];
} else {
[self selectADate:[sender locationInView:self.view]];
}
}
}
}
}
Here is the currently nonworking iPhone code:
-(void)iphoneSelectADate: (CGPoint)p
{
UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - 216, 320, 216)];
[datePicker setDate:[NSDate date]]; //This is the default
[datePicker setHidden:NO];
[self.view addSubview:datePicker];
}
If I step through in the debugger, I see this code is executed, but the datepicker does not display.

UIDatePicker inherits from UIView, so you can add it just like a UILabel. Make sure you give it a frame.
Something like this would work for the bottom of an iPhone screen:
datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - 216, 320, 216)];
[datePicker setDate:[NSDate date]]; //This is the default
[self.view addSubview:datePicker];
It sounds like you likely have a subview layering issue, not a UIDatePicker issue though.
If that doesn't work, post some of your code and we'll help figure it out.

Not sure if this will help, but UI changes for views that are already present require to be dispatched using the main_queue
for e.g.
dispatch_async(dispatch_get_main_queue(), ^
{
[self.view addSubview:yourSubview];
});

I think I may have found the key to my problem. After reading through this document on the various places to place orientation-related code, I decided on viewWillLayoutSubviews. I read through the document again and decided to try putting that code in viewWillAppear instead, and that seems to have resolved the problem.
The change to using viewWillAppear also required implementation of willAnimateRotationToInterfaceOrientation:duration:
It looks like viewWIllLayoutSubviews is needed for iPad but not iPhone, so I've also added this:
-(void)viewWillLayoutSubviews
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
//iPhone code goes here (empty, since calling showMonthContainingDate: doesn't work from here in iPhone
} else {
//ipad code goes here
NSDate *dayToDisplay = self.displayedDate;
[self showMonthContainingDate:dayToDisplay];
//iPad uses wrong dimensions unless the routine is called from here.
}
}
One final note. There is one scenario where the orientation of the device is not set correctly -- that is landscape on an iPhone at launch. According to this answer to another question the iPhone always launches in portrait unless it is a landscape-only app.

Related

How to set a view to a tag set in code not in Interface Builder?

I have an app that uses 4 different xibs, lets call them 1-4
So you start on view 1, if you press the button it takes you to view 2, on view 2, you have a back button (which takes you to 1) and forward button that takes you to 3 etc
Anyway, I am removing the next page buttons, and have added a swipe control instead of pressing a button, you can swipe to the next page.
However, I need to know how I can call a tagged view, using the swipe.
At the moment, the UIButton for next page is set in IB as tag 1
This is my swipe code (this is page 1 so only has a swipe left)
- (IBAction)swipeLeftDetected:(UIGestureRecognizer *)sender {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
Page2ViewController *UIViewController =
[[Page2ViewController alloc] initWithNibName:#"Page2ViewController~ipad" bundle:nil];
[self presentModalViewController:UIViewController animated:YES];
}else{
Page2ViewController *UIViewController =
[[Page2ViewController alloc] initWithNibName:#"Page2ViewController" bundle:nil];
[self presentModalViewController:UIViewController animated:YES];
Page2ViewController *VC = [[Page2ViewController alloc] initWithNibName:#"Page2ViewController" bundle:nil];
[self presentModalViewController:VC animated:YES];
[self.view removeGestureRecognizer:[self.view.gestureRecognizers lastObject]];
[VC release];
}
}
Whereabout in that code, can I tell it to swipe to tag 1?
Would appreciate any help :)
Thanks,
Chris
---- Updated FAO Rob;
In the appdelegate.m
- (void)swicthView:(int)viewControllerIndex :(CGRect)viewRect {
if (viewControllerIndex < 0 || viewControllerIndex > viewControllers.count) {
//invalid index passed to function - do nothing
}else{
if (subViewForceUseNibSize == NO) {
//pass the view frame size at runtime
if (CGRectIsEmpty(viewRect) || viewControllerIndex == 0) {
//no frame size so force full screen
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
viewRect =CGRectMake(0, 0, 320, 480);
}else{
viewRect = CGRectMake(0, 0, 768, 1024);
}
}
}else{
//force use the nib size, so reduce size of NIB to leave display of NIB main nib below
viewRect = ((UIViewController *)[viewControllers objectAtIndex:viewControllerIndex]).view.frame;
}
}
//swicth our view
if (viewControllerIndex == 0) {
/*
for (UIView *subview in window.rootViewController.view.subviews) {
[window.rootViewController.view sendSubviewToBack:subview];
}
*/
for (int x = 1; x<[viewControllers count]; x++) {
if (((UIViewController *)[viewControllers objectAtIndex:x]).view.superview != nil) {
[window.rootViewController.view sendSubviewToBack:((UIViewController *)[viewControllers objectAtIndex:x]).view];
}
}
[window bringSubviewToFront:((UIViewController *)[viewControllers objectAtIndex:0]).view];
return;
}
if (((UIViewController *)[viewControllers objectAtIndex:viewControllerIndex]).view.superview != nil) {
((UIViewController *)[viewControllers objectAtIndex:viewControllerIndex]).view.frame = viewRect;
[window.rootViewController.view bringSubviewToFront:((UIViewController *)[viewControllers objectAtIndex:0]).view];
[window.rootViewController.view bringSubviewToFront:((UIViewController *)[viewControllers objectAtIndex:viewControllerIndex]).view];
}else{
((UIViewController *)[viewControllers objectAtIndex:viewControllerIndex]).view.frame = viewRect;
[window.rootViewController.view bringSubviewToFront:((UIViewController *)[viewControllers objectAtIndex:0]).view];
[window.rootViewController.view addSubview:((UIViewController *)[viewControllers objectAtIndex:viewControllerIndex]).view];
}
}
Looking at the revised code sample, it is clear that there is a UIAppDelegate method called swicthView [sic] that is used for transitioning between five different view controllers, all of which are loaded simultaneously. Given this structure, it is advised that you have a property to keep track of which of the five pages is loaded, and based on the left or right swipe, invoke swicthView to transition to that controller. Thus:
#interface ViewController ()
#property (nonatomic) NSInteger currentPage;
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.currentPage = 0;
UISwipeGestureRecognizer *gesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleLeftSwipe:)];
gesture.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:gesture];
[gesture release];
gesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleRightSwipe:)];
gesture.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:gesture];
[gesture release];
// the rest of the viewDidLoad
}
- (void)handleLeftSwipe:(UISwipeGestureRecognizer *)gesture {
if (self.currentPage < 4)
{
++self.currentPage;
[UIAppDelegate swicthView:self.currentPage :CGRectZero];
}
}
- (void)handleRightSwipe:(UISwipeGestureRecognizer *)gesture {
if (self.currentPage > 0)
{
--self.currentPage;
[UIAppDelegate swicthView:self.currentPage :CGRectZero];
}
}
Frankly, I'd strong advise retiring the swicthView design and rather employing a custom container view controller. If you watch WWDC 2011 - Implementing a UIViewController containment, you'll see a good introduction about the importance of keeping a view controller hierarchy synchronized with a view hierarchy, and see some practical demonstrations of custom containers.
The original answer, provided below, was based upon the original snippet of code that was performing presentViewController. It turns out that a very different solution was called for, outlined above, but I retain the original answer for historical purposes:
Original answer:
I assume you have the following sort of code in viewDidLoad:
UISwipeGestureRecognizer *gesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleLeftSwipe:)];
gesture.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:gesture];
And then you gesture handler could be:
- (void)handleLeftSwipe:(UISwipeGestureRecognizer *)gesture
{
NSString *nibName;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
nibName = #"Page2ViewController~ipad";
else
nibName = #"Page2ViewController";
Page2ViewController *controller = [[Page2ViewController alloc] initWithNibName:nibName bundle:nil];
// if supporting iOS versions earlier than 5.0, then you should use:
//
// [self presentModalViewController:controller animated:YES];
//
// otherwise you should use presentViewController as done below.
[self presentViewController:controller animated:YES completion:nil];
[controller release];
}
Note, I'm don't remove the gesture (unless you really don't want the gesture there when you return back to this view, which is unlikely). Also note, I'm creating controller, presenting, and releasing.
I'm not understanding your repeated reference to tag properties in this context, as numeric tag values are used for identifying subviews of a view, not for identifying view controller or anything like that. So you say "UIButton for next page is set in IB as tag 1" and later you ask "Whereabout ... can I tell it to swipe to tag 1?" It doesn't make sense to "swipe to a button". You could, though, have the two handlers, the button's IBAction (which I'll call onPressNextButton ... I don't know what you called it) and the handleLeftSwipe call the same method, e.g.:
- (void)handleLeftSwipe:(UISwipeGestureRecognizer *)gesture
{
[self goToNextViewController];
}
- (IBAction)onPressNextButton:(id)sender
{
[self goToNextViewController];
}
- (void)goToNextViewController
{
NSString *nibName;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
nibName = #"Page2ViewController~ipad";
else
nibName = #"Page2ViewController";
Page2ViewController *controller = [[Page2ViewController alloc] initWithNibName:nibName bundle:nil];
[self presentViewController:controller animated:YES completion:nil];
[controller release];
}
References:
presentViewController, the preferred method for modal transitions.
presentModalViewController, the now deprecated method that you use if you need backward compatibility for iOS versions prior to 5.0.
Naming basics in the Coding Guidelines for Cocoa, for advice in naming variables and methods. Note variables generally start with lowercase letters and classes generally start with uppercase letters.

UISegmentedControl click event not working in IOS 6

I have created a mapview, with page curl feature in it. The mapview is having a toolbar, with a page curl button. On clicking the button, the mapview page curls. Here is the code.
-(IBAction) onPageCurl:(id)sender{
pageCurlViewController = [[MyMapViewPageCurlViewController alloc] initWithNibName:#"MyMapViewPageCurlViewController" bundle:nil];
[pageCurlViewController.navigationController.toolbar setHidden:NO];
[pageCurlViewController setModalTransitionStyle:UIModalTransitionStylePartialCurl];
[pageCurlViewController setToolbarItems:toolbarItems];
[[self navigationController] presentModalViewController:pageCurlViewController animated:YES];
[pageCurlViewController getMapView:&mapView];
[pageCurlViewController release];
}
As the mapview page curls, I have a new viewcontroller underneath it. The new view controller has a segmented control with 3 segments.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self.navigationController.toolbar setHidden:NO];
[directionSearchSegmentedControl addTarget:self action:#selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
directionSearchSegmentedControl.selectedSegmentIndex = selectedIndex;
UIBarButtonItem *directionSearchSegmentedControlButton = [[[UIBarButtonItem alloc] initWithCustomView:directionSearchSegmentedControl] autorelease];
NSArray *toolbarItems = [NSArray arrayWithObjects: navigatorButton , flexibleSpace, directionSearchSegmentedControlButton, flexibleSpace, pageCurlButton, nil];
[self setToolbarItems:toolbarItems];
[self.navigationController.toolbar setHidden:NO];
}
I have standard/satellite/hybrid view of the map on clicking each segments in the segmented controller.
- (void)segmentAction:(id)sender
{
[self dismissModalViewControllerAnimated:YES];
if([sender selectedSegmentIndex] == 0){
selectedIndex = 0;
pageCurlMapView.mapType = MKMapTypeStandard;
}
if([sender selectedSegmentIndex] == 1){
selectedIndex = 1;
pageCurlMapView.mapType = MKMapTypeSatellite;
}
if([sender selectedSegmentIndex] == 2){
selectedIndex = 2;
pageCurlMapView.mapType = MKMapTypeHybrid;
}
if([sender selectedSegmentIndex] == 2){
}
directionSearchSegmentedControl.momentary = YES;
selectedIndex = directionSearchSegmentedControl.selectedSegmentIndex;
}
The page curl feature is working fine. As the page curls, as mentioned before, I have a segmented control in the new view. But the the segmented control is not working properly in IOS 6. I have debugged and checked. On the click of the segments, the control doesn't enter the event method.
Its still working fine in the previous versions of IOS, but not in IOS 6. Cant figure out, what is wrong. Help needed.
If you look at the Xcode console when the app launches, do you see a message like this:
Applications are expected to have a root view controller at the end of application launch
If so, then your you problem could be due to changes in how the root view controller needs to be set up for iOS 6.
See here for info on how to address the problem.
Sorry if this is kinda late, but I have been working on something similar in my app. Honestly, I just used a simple switch method in order to change the map type. The code is below.
- (IBAction)toggle:(id)sender {
switch ([sender selectedSegmentIndex]) {
case 0:
{
[self.mapView setMapType:MKMapTypeStandard];
}break;
case 1:
{
[self.mapView setMapType:MKMapTypeHybrid];
}break;
case 2:
{
[self.mapView setMapType:MKMapTypeSatellite];
}break;
}
}
Now I have not tried using this with multiple view controllers so this may only work with the one view controller. I just started programming on iOS so bear with me.. I'm gonna try to add the page curl effect to my app but all I have so far is a map view and a button that when it's pushed, zooms into the users location and the user is able to change the map type..
P.S. This is a Segmented Control set as a Value Changed action named "toggle" if that helps...

iOS switching view controllers depending on the device orientation

I'm developing an Augmented Reality application, everything worked properly till now that I need two different kind of visualization (AR and Map) depending on the device orientation. In particular the application should use the landscapeViewController when the device is in landscape mode while it should use another controller (named faceUpViewController ) when the device's orientation is "face up". I tried doing it with two simple view controllers and it works fine. The problem happens when the landscapeViewController uses the AR controller. The view is completely white and I don't understand why. Both the two controllers are "contained" by a Root View Controller. I'm doing everything by coding so without nib files. Here is the code:
RootViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(deviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
}
- (void)deviceOrientationDidChange:(NSNotification *)notification{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationLandscapeLeft) {
if (self.landscapeViewController.view.superview == nil) {
if (self.landscapeViewController == nil) {
LandscapeViewController *lvc = [[LandscapeViewController alloc] init];
self.landscapeViewController = lvc;
[lvc release];
}
[self.faceUpViewController.view removeFromSuperview];
[self.view addSubview:self.landscapeViewController.view];
}
}
if (orientation == UIDeviceOrientationFaceUp) {
if (self.faceUpViewController.view.superview == nil) {
if (self.faceUpViewController == nil) {
FaceUpViewController *fvc = [[FaceUpViewController alloc] init];
self.faceUpViewController = fvc;
[fvc release];
}
[self.landscapeViewController.view removeFromSuperview];
[self.view addSubview:self.faceUpViewController.view];
}
}
}
#end
LandscapeViewController.m
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
UIView *landscapeView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
landscapeView.backgroundColor = [UIColor yellowColor];
self.view = landscapeView;
[landscapeView release];
ARController *arC = [[ARController alloc] initWithViewController:self];
arC.landscapeViewController = self;
self.arController = arC;
[arC release];
}
//When the view appear present the camera feed
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[_arController presentModalARControllerAnimated:NO];
}
FaceUpViewController.m
- (void)loadView
{
UIView *faceUpView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
faceUpView.backgroundColor = [UIColor blueColor];
self.view = faceUpView;
[faceUpView release];
}
ARController.m Very simple version
- (id) initWithViewController:(UIViewController *)theView{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.rootController = theView;
//Retrieve screen bounds
CGRect screenBounds = [[UIScreen mainScreen] bounds];
UIView *overlaidView = [[UIView alloc] initWithFrame: screenBounds];
self.overlayView = overlaidView;
[overlaidView release];
self.rootController.view = overlayView;
// Initialise the UIImagePickerController
UIImagePickerController *picker= [[UIImagePickerController alloc] init];
self.pickerController = picker;
[picker release];
self.pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
self.pickerController.cameraViewTransform = CGAffineTransformScale(
self.pickerController.cameraViewTransform, 1.0f, 1.12412f);
self.pickerController.showsCameraControls = NO;
self.pickerController.navigationBarHidden = YES;
self.pickerController.cameraOverlayView = _overlayView;
}
return self;
}
- (void)presentModalARControllerAnimated:(BOOL)animated{
[self.rootController presentModalViewController:[self pickerController] animated:animated];
self.overlayView.frame = self.pickerController.view.bounds;
}
#end
I say again that I'm doing everything by coding thereby without nib files.
I really appreciate any advice!
Thanks
The primary problem with adding and removing your "child" view controllers' views as you've done here is that the view controller life cycle methods (viewWillAppear:, viewDidAppear:, etc.) won't ever get called on your child view controllers. Containers like UINavigationController and UITabBarController have always known how to delegate methods like these appropriately to their children, but UIViewController didn't officially support the ability to nest view controllers under your own custom container before iOS 5. It was possible, but it took a lot more work to do it right.
If you want to stick with the approach of adding and removing subviews, you have two options:
Require iOS 5+, and call addChildViewController:, removeFromParentViewController,
transitionFromViewController:toViewController:duration:options:animations:completion:,
willMoveToParentViewController:, and
didMoveToParentViewController: as described in the Implementing a Container View Controller section of the UIViewController Class Reference.
To support older iOS versions, you'll have to override many of the methods of the UIViewController class and delegate those calls manually to your child view controllers to make them behave as expected. I'd pay particular attention to the sections titled, "Responding to View Events", and "Responding to View Rotation Events" in the UIViewController Class Reference.
A different approach for pre-iOS 5 support is to present your child view controllers using presentModalViewController:animated: rather than adding their views as subviews to a container. Apple describes this approach in the View Controller Programming Guide for iOS under the section, Creating an Alternate Landscape Interface. The advantage of this approach is that your child view controllers are officially supported as first-class members of the view controller hierarchy, so UIKit will automatically manage their life cycles appropriately. You won't have to override and delegate all those methods manually.
You might want to try getting your acceptance rate up a little bit - more people would be willing to help you.
Anyway, wild guess: in your root controller, try putting the contents of
deviceOrientationDidChange
into
deviceOrientationWillChange.

how to customise color of EKEventEditView displayed by EKEventView?

BACKGROUND:
I now can see how to customise the color of a EKEventView, which is an apple view that you can use to display a calendar event. The code is per my post here: is this code future proof for customising color of EKEventViews (code attached)
If this view is EDIT'able however the apple EKEventView class then shows a modal "EKEventEditView" view.
QUESTION:
My question is how do I customise the color of EKEventEditView, for which the view wasn't trigged by my code, but rather by the apple code in the EKEventView.
LINKS TO API:
EKEventViewController: http://developer.apple.com/library/ios/#documentation/EventKitUI/Reference/EKEventViewControllerClassRef/Reference/Reference.html
EKEventEditViewController - http://developer.apple.com/library/ios/#documentation/EventKitUI/Reference/EKEventEditViewControllerClassRef/Reference/Reference.html
I don't know how Apple will respond to this code, but it works :)
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(willShowController:)
name:#"UINavigationControllerWillShowViewControllerNotification"
object:nil];
And selector method:
-(void)willShowController:(NSNotification*)sender{
NSLog(#"%# ", [sender description]);
UIViewController *controller = (UIViewController*)[sender object];
if ([controller isKindOfClass:EKEventEditViewController.class]){
UITableViewController *rootController = (UITableViewController*)[(UINavigationController*)controller visibleViewController];
UITableView *tv = (UITableView*)[rootController view];
[tv setBackgroundColor:[UIColor redColor]];
UIView *v = (UIView*)[[tv visibleCells] objectAtIndex:0];
v.backgroundColor = [UIColor blueColor];
}
}
There is only one string UINavigationControllerWillShowViewControllerNotification which you cannot find in SDK. But in this case it's only the string..
Hope this help you.
I am not sure as I have never had to what you are asking, but since it subclass UIViewController try doing you color stuff on yourEventViewController.view.
Let me know if that helps.

presentModalViewController doesn't rotate properly in iPhone / iPad

I have a viewController called MainViewController, which has a UIButton. When tapped, this button loads another viewController, called ModalSelector like this:
- (IBAction)showModalSelector:(id)sender {
ModalSelector *modal = [[ModalSelector alloc]
initWithNibName:#"modalSelector" bundle:nil];
modal.modalPresentationStyle = UIModalPresentationFormSheet;
modal.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
modal.modalInPopover = YES;
modal.issues = issuesForModal;
modal.parent = self;
[self presentModalViewController:modal animated:YES];
[modal.view setFrame:CGRectMake(-80, 20, 700, 400)];
[issuesForModal release];
[modal release];
}
However, when I rotate the device in the simulator, neither view rotates properly, even though I have this in both viewControllers:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
How can I make it rotate properly?
Thanks
I've discovered there's not a problem with the code, but with the simulator itself. When I test it on the actual device, it works perfectly.