Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chen8002004

macrumors newbie
Original poster
May 22, 2011
26
0
I face a very strange UIButton problem. When I press the button and move (do not release), the highlighted area goes to wrong areas (areas that beyond the scope of the view). However, the key inside up event works. Can anyone help?
Declaration:
Code:
@interface datapickerForDayViewController : UIViewController 
{
    UIDatePicker *datePicker;
    UIButton *button;
}
@property ( nonatomic, retain ) IBOutlet UIDatePicker *datePicker;
@property ( nonatomic, retain ) IBOutlet UIButton     *button;;
-(IBAction)buttonPressed: (id)sender;
-(id)initMyFrame:(CGRect)_rect;
@end
Definition:
Code:
@implementation datapickerForDayViewController
@synthesize datePicker;
@synthesize button;
-(id)initMyFrame:(CGRect)_rect
{
    self.view.frame=_rect;
    datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 0, _rect.size.width, (_rect.size.height/2))];    
    datePicker.datePickerMode=UIDatePickerModeDate;
    UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    self.button = myButton;
    button.frame = CGRectMake((_rect.size.width/4), (_rect.size.height *2/3), (_rect.size.width/2), (_rect.size.height/6));
    [button setTitle:@"Select Date" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:datePicker];
    [self.view addSubview:button];
    return self;
}
-(IBAction) buttonPressed: (id)sender
{
    ...
}
@end
Use:
Code:
datapickerForDayViewController* myDatePickController=[[datapickerForDayViewController alloc] initWithNibName:nil bundle:nil];
            [myDatePickController initMyFrame:CGRectMake(410, 185, 572, 535)];
            [superview addSubview:myDatePickController.view];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.