Question

I am developing a Universal app, and there is a UIButton in it which works fine with iPhone but when I click it in iPad it requires many click attempts to get the touch event occur.

e.g. after 5-6 clicks it executes click event.

Below is UIButton code. Please help.

UIView *footer = [[[UIView alloc] initWithFrame:(CGRectMake(0, 0, self.tableView.frame.size.width, 54))] autorelease];
float buttonWidth = (int)((self.tableView.frame.size.width - 12 - 12) / 3);
float buttonHeight = 44;

if (clientState.Devicetype == 1) // 1=Ipad
    buttonHeight = 90;
cash = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];

cash.frame = CGRectMake(6, 10, buttonWidth, buttonHeight); 
[cash setTitle:@"Cash" forState:UIControlStateNormal];
[cash setTitleColor:[UIColor lightGrayColor] forState:UIControlStateDisabled];
[cash addTarget:self action:@selector(handleCash:) forControlEvents:UIControlEventTouchUpInside];
cash.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin;

if (clientState.Devicetype == 1) // 1=Ipad
{
    cash.titleLabel.font = [UIFont systemFontOfSize:28];    
}

[footer addSubview:cash];

self.tableView.tableFooterView = footer;
Was it helpful?

Solution

You should check to make sure that your buttons are the correct size:

[cash sizeToFit]

I've experienced that if some other view is blocking it (and you click on that part of your button it won't fire off the event) it will take several clicks because you eventually press the button where it's not being covered. So make sure no other frame/bounds is over the top of your button and make sure your button is sized correctly.

OTHER TIPS

I agree with @Inturbidus that it's probably another transparent view covering part of the button. I find the best way to troubleshoot this is to change the background color on all my other views (scrollviews, etc) to make sure they are behaving like I think they are. Sometimes it will surprise you when you see where they are actually positioned with background color turned on.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top