views:

21

answers:

2

hello this is my code is it wrong

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"Inside touchesBegan");
    UITouch *touch = [[event touchesForView:self.view] anyObject];
    CGPoint location = [touch locationInView:touch.view];
     NSLog(@"pointx: %f pointy:%f", location.x, location.y);
     NSLog(@"about to enter do");
    if(CGRectContainsPoint(b_do.frame, location))
    {
        NSLog(@"inside do");
        [self b_do];
        [b_do setHighlighted:YES];

    }
}

in the log i got this :

2010-10-15 21:00:42.555 phone[14280:207] Inside touchesBegan
2010-10-15 21:00:42.557 phone[14280:207] pointx: 0.000000 pointy:0.000000
2010-10-15 21:00:42.557 phone[14280:207] about to enter do
2010-10-15 21:00:42.558 phone[14280:207] about to exit touchesBegan
A: 

The line with self.view might be the problem. The UITouch delegate is usually the UIView subclassed object itself (since it's a view, just use "self"), not a view controller (where self.view would reference the controller's view).

hotpaw2
if i write self a warning occur warning: incompatible Objective-C types 'struct MainViewController *', expected 'struct UIView *' when passing argument 1 of 'touchesForView:' from distinct Objective-C type
Bobj-C
Then you might have this method inside the wrong class, controller instead of view subclass.
hotpaw2
A: 

my peoblem solved by replace this code:

UITouch *touch = [[event touchesForView:self.view] anyObject];

By this one :

UITouch *touch = [touches anyObject];
Bobj-C