if (CGRectContainsPoint([route frame],point))
{
[self pickerShow];
}
wt u need then?
It should only go to pickerShow if the UITectField route it clicked/tapped. I expect the method touchesBegan to be called when I click on the screen. Is my understanding of this correct ?
I want to click on a text field and have a UIPicker load as view/subview. When I select a value from the picker is should populate the text box. The UIPicker view/subview should have a DONE button on it as well so it disappears when clicked.
I'm really struggling with this, I've been at it for a few days.
I don't think your quite right in what your saying. The statement:
if (CGRectContainsPoint([route frame],point))
checks the area of the screen the user is clicking on, if its within the frame of route (which is my UITextField) then it should call the pickerShow method.
then how u calculate,
float tipTotal = [billTotal.text floatValue] * tipSelected;
if billTotal.text is 0 then tipTotal always zero... u r not assigning any value to it...
The sample code in the link is not mine, my code is based off it. It doesn't appear to be 100% complete, but if you populate billtotal.text with a value, it works. I'm not that concerned with the calculation just how the UIPicker is loaded.
Okay, I'm going to add a bit more information to this to see if anyone can help with the solution.
When my App runs RootViewController is loaded first, I have a number of buttons on this screen that call other ViewControllers.
RootViewController.m
Code:
-(IBAction)newWorkoutButton
{
[self presentModalViewController:newWorkoutViewController animated:YES];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"Screen has been tapped");
}
Note, that when I click on the RootViewController screen a message is written to the log NSLog file as above. I click on the button to load the newWorkoutViewController. This works with no problems.
Okay, I'm going to add a bit more information to this to see if anyone can help with the solution.
When my App runs RootViewController is loaded first, I have a number of buttons on this screen that call other ViewControllers.
RootViewController.m
Code:
-(IBAction)newWorkoutButton
{
[self presentModalViewController:newWorkoutViewController animated:YES];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"Screen has been tapped");
}
Note, that when I click on the RootViewController screen a message is written to the log NSLog file as above. I click on the button to load the newWorkoutViewController. This works with no problems.
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)routePicker
{
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)routePicker numberOfRowsInComponent:(NSInteger)component
{
return[list count];
}
-(NSString *)pickerView:(UIPickerView *)routePicker titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return[list objectAtIndex:row];
}
-(void)pickerView:(UIPickerView *)routePicker didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSLog(@"Selected item: %@ index of selected item: %i",[list objectAtIndex:row], row);
/*
// Fill textbox as user scrolls through UIPickerView selection.
if (component == kMyComponent)
{
NSString *myValue = [self.infoTypes objectAtIndex:row];
NSLog(@"hello you selected the value: %@", myValue);
}
*/
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"New Workout Screen tapped");
/*
UITouch *touch;
touch=[touches anyObject];
CGPoint point=[touch locationInView:self.view];
if (CGRectContainsPoint([route frame],point))
//if (CGRectContainsPoint([self.view frame],point))
{
[self pickerShow];
}*/
}
-(IBAction)doneButton
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
CGAffineTransform transform = CGAffineTransformMakeTranslation(0, 480);
pickerView.transform = transform;
[UIView commitAnimations];
}
-(IBAction)pickerShow
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
CGAffineTransform transform = CGAffineTransformMakeTranslation(0, 240);
pickerView.transform = transform;
[self.view addSubview:pickerView];
[UIView commitAnimations];
}
-(void)viewDidLoad
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
CGAffineTransform transform = CGAffineTransformMakeTranslation(0, 480);
pickerView.transform = transform;
//[self.view addSubview:pickerView];
[UIView commitAnimations];
// When the view loads, run this action.
[super viewDidLoad]; // This NEEDS to be here or the application will not work!
route.delegate = self;
//[super viewDidLoad];
counterInt = 0;
//NewWorkoutViewController.userInteractionEnabled = YES;
list = [[NSMutableArray alloc] init];
[list addObject:@"Benbulben"];
[list addObject:@"Strandhill"];
[list addObject:@"Sugar Loaf"];
[list addObject:@"Everest"];
[list addObject:@"Bray Head"];
[list addObject:@"Howth Head"];
[list addObject:@"Marley Park"];
}
When the screen is clicked, I'm method touchesBegan to be called and something to be written to the log file. But nothing happens.
Has anyone any ideas ?
if touchesBegan method is not getting called there must be some problem with userInteractionEnabled Property of view.
to get touchevent's ur view's userInteractionEnabled property must be TRUE and Set your Textfield's userInteractionEnabled = FALSE;
in NewWorkoutViewController I have two other buttons which can call two other view controllers. I didn't have these setup correctly, so the when the screen was clicked/tapped it wasn't registering.