Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 07-13-2010, 09:11 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 129
stephen is on a distinguished road
Default touchesBegan - not working

Hello,

I have the following code in place:

Code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
	UITouch *touch;
	touch=[touches anyObject];
	CGPoint point=[touch locationInView:self.view];
	
	if (CGRectContainsPoint([route frame],point))
	{
		[self pickerShow];
	}
}
The method is not executing, has anyone any ideas, I'm really stuck on this ?

I've based my code from the following sample app: PickerTut 2.zip

Regards,
Stephen
stephen is offline   Reply With Quote
Old 07-13-2010, 09:16 AM   #2 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 100
mobin_shaikh is on a distinguished road
Default

Hi stephen,

according to ur code control goes to,

if (CGRectContainsPoint([route frame],point))
{
[self pickerShow];
}

wt u need then?
mobin_shaikh is offline   Reply With Quote
Old 07-13-2010, 09:21 AM   #3 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 129
stephen is on a distinguished road
Default

Quote:
Originally Posted by mobin_shaikh View Post
Hi stephen,

according to ur code control goes to,

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 ?
stephen is offline   Reply With Quote
Old 07-13-2010, 09:22 AM   #4 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 100
mobin_shaikh is on a distinguished road
Default

It is one and same behaviour, wt u actually want to do?

if u want to detect touche on screen then just replace single line of ur code to,

if (CGRectContainsPoint([self.view frame],point))

Last edited by mobin_shaikh; 07-13-2010 at 09:25 AM.
mobin_shaikh is offline   Reply With Quote
Old 07-13-2010, 09:29 AM   #5 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 129
stephen is on a distinguished road
Default

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.
stephen is offline   Reply With Quote
Old 07-13-2010, 09:31 AM   #6 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 129
stephen is on a distinguished road
Default

I've tried your change but it didn't work.

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.

Stephen

Last edited by stephen; 07-13-2010 at 09:33 AM.
stephen is offline   Reply With Quote
Old 07-13-2010, 09:34 AM   #7 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 100
mobin_shaikh is on a distinguished road
Default

what is the initial value of ur billTotal.text when view is loaded?
mobin_shaikh is offline   Reply With Quote
Old 07-13-2010, 09:39 AM   #8 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 129
stephen is on a distinguished road
Default

Quote:
Originally Posted by mobin_shaikh View Post
what is the initial value of ur billTotal.text when view is loaded?
nothing, its empty.
stephen is offline   Reply With Quote
Old 07-13-2010, 09:41 AM   #9 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 100
mobin_shaikh is on a distinguished road
Default

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...
mobin_shaikh is offline   Reply With Quote
Old 07-13-2010, 09:46 AM   #10 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 129
stephen is on a distinguished road
Default

Quote:
Originally Posted by mobin_shaikh View Post
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.
stephen is offline   Reply With Quote
Old 07-13-2010, 09:54 AM   #11 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 100
mobin_shaikh is on a distinguished road
Default

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
CGAffineTransform transform = CGAffineTransformMakeTranslation(0, 240);
pickerView.transform = transform;
[self.view addSubviewickerView];
[UIView commitAnimations];

here you created customize UIView and just add that UIView as a subView to ur main view... wt is difficult in it?
mobin_shaikh is offline   Reply With Quote
Old 07-13-2010, 10:15 AM   #12 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 129
stephen is on a distinguished road
Default

Quote:
Originally Posted by mobin_shaikh View Post
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
CGAffineTransform transform = CGAffineTransformMakeTranslation(0, 240);
pickerView.transform = transform;
[self.view addSubviewickerView];
[UIView commitAnimations];

here you created customize UIView and just add that UIView as a subView to ur main view... wt is difficult in it?
The problem is the code above is not being called when I click on my textfield.

Last edited by stephen; 07-13-2010 at 10:32 AM.
stephen is offline   Reply With Quote
Old 07-13-2010, 12:29 PM   #13 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 129
stephen is on a distinguished road
Default

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.

NewWorkoutViewController.h
Code:
@interface NewWorkoutViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate, UITextFieldDelegate> {

	IBOutlet UIView *pickerView;
	IBOutlet UIPickerView *routePicker;
	IBOutlet UITextField * route;
	NSMutableArray *list;
	float tipSelected;
}

-(IBAction)pickerShow;
-(IBAction)doneButton;

@end
NewWorkoutViewController.m
Code:
-(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 ?
stephen is offline   Reply With Quote
Old 07-13-2010, 11:18 PM   #14 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 82
smsawant is on a distinguished road
Default

Quote:
Originally Posted by stephen View Post
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.

NewWorkoutViewController.h
Code:
@interface NewWorkoutViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate, UITextFieldDelegate> {

	IBOutlet UIView *pickerView;
	IBOutlet UIPickerView *routePicker;
	IBOutlet UITextField * route;
	NSMutableArray *list;
	float tipSelected;
}

-(IBAction)pickerShow;
-(IBAction)doneButton;

@end
NewWorkoutViewController.m
Code:
-(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;

Hope this will help you.
__________________
You can mail me at sanketsawant1@gmail.com
smsawant is offline   Reply With Quote
Old 07-14-2010, 04:16 AM   #15 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 129
stephen is on a distinguished road
Default

Thanks for the response but I've checked this already, user interactions are set correctly.
stephen is offline   Reply With Quote
Old 07-14-2010, 05:01 AM   #16 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 100
mobin_shaikh is on a distinguished road
Default

but on my side ur code executing correctly....
mobin_shaikh is offline   Reply With Quote
Old 07-14-2010, 05:16 AM   #17 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 129
stephen is on a distinguished road
Default

Is it.....are you getting messages written to the log file from the NewWorkoutViewController.m
stephen is offline   Reply With Quote
Old 07-14-2010, 05:57 AM   #18 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 129
stephen is on a distinguished road
Default

Problem solved...

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.

Thanks everyone for the help.
stephen is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 383
11 members and 372 guests
AragornSG, baja_yu, ChrisYates, davejas69, guusleijsten, hussain1982, jbro, Kryckter, locombiano89, Mah6447, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,646
Threads: 94,111
Posts: 402,862
Top Poster: BrianSlick (7,990)
Welcome to our newest member, locombiano89
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:40 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0