UITableView Add FooterView Button Sometimes Tap Doesn't Perform Action - ios

I have a simple UITableView that I've added a UIButton to the Footer.
Similar to this:
self.btn =[UIButton buttonWithType:UIButtonTypeCustom];
self.btn.backgroundColor = darkPurple;
[self.btn setTitle:#"Submit" forState:UIControlStateNormal];
[self.btn addTarget:self action:#selector(btnTapped:) forControlEvents:UIControlEventTouchUpInside];
[self.btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
self.btn.frame=CGRectMake(0, 0, self.tableView.frame.size.width, 100);
self.btn.showsTouchWhenHighlighted = true;
self.tableView.tableFooterView = self.btn;
Sometimes when I get scrolled to the bottom of the TableView if it isn't completely settled the Button won't perform the action. Sometimes it will flash (showsTouchWhenHighlighted) but I'll need to tap it again.
What am I missing here? I've tried solutions like this but it doesn't appear to work.
UIButton touch is delayed when in UIScrollView
I want to it process always, even if the scroll isn't settled and not delay.

What am I missing here?
Nothing. That's just how touches work on iOS. You can see the same thing in Mobile Safari: if the page is still scrolling, tapping a link doesn't work. You have to wait until the page is completely stopped ("settled", as you rightly say).

Related

Delay of highlight in UIButton in UIView

Alright so normally this problem happens in a tableView's scrollView or scrollView of some sort but I am having a "halfway delay" on a UIButton that is contained in simply a UIView. Here's my code:
UIButton *brightnessUpButton = [UIButton buttonWithType:UIButtonTypeCustom];
[brightnessUpButton setFrame:CGRectMake(260, 0, 60, 144)]; //y:5 height:80
brightnessUpButton.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 50, 0);
UIButton *brightnessDownButton = [[UIButton alloc] initWithFrame:CGRectMake(5, 24, 40, 40)];
[brightnessUpButton setImage:[UIImage imageNamed:#"brightnessUp.png"] forState:UIControlStateNormal];
[brightnessUpButton setImage:[UIImage imageNamed:#"brightnessUpHighlighted.png"] forState:UIControlStateHighlighted];
[brightnessDownButton setImage:[UIImage imageNamed:#"brightnessDown.png"] forState:UIControlStateNormal];
[luxView addSubview:brightnessUpButton];
[luxView addSubview:brightnessDownButton];
So the problem is currently with brightnessUpButton. As you can see I did nothing but set the frame and content Insets. So the problem is when you click on the button. If you click below where the image appears in the button you get a 1-2 second delay for the highlight of the button. If you click on the image, you get an immediate highlight, and when you click above the image of the UIButton you get an immediate highlight.
This behavior makes no sense to me because the UIButton is added to a UIView, not a scrollView of any sort and the highlighting only happens immediately with half of the button. I have tried:
1) setting the imageEdgeInsets and contentEdgeInsets as apprropriate
2) Using the View debugger to see if there's some additional object interfering with the button - of which the result was NONE, the UIView exists on top of the UIView and that is all.
What could possibly be causing this weird behavior?

programmat button and storyboard button

I have one button and one search field in navigation bar and i added a new button by code from one class for all view.
The problem is: with the button view the other button and the search field added with storyboard are not more touchable and not working.
UIImage * buttonImage = [UIImage imageNamed:#"chat-notify.png"];
button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self
action:#selector(goChat)
forControlEvents:UIControlEventTouchDown];
//[button setTitle:#"1" forState:UIControlStateNormal];
button.frame = CGRectMake(280.0, 25.0, 30.0, 30.0);
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
[self.view addSubview:button];
and then in the controller:
notificationViewController* notification = [[notificationViewController alloc]init];
//[notification methodA];
[notification makeButtonNotification];
[self.view addSubview:notification.view];
Does anyone know where is my mistake?
Thanks
Why are you adding the button surely having it there and changing it's hidden state would be easier then you can keep it all in the storyboard
UIControlEventTouchUpInside
is what you should use not "UIControlEventTouchDown"
TouchUpInside is usually the event where you trigger the action from a button. It's when the user is lifting up from the button after pressing it. You don't want to trigger the action on Touch Down as the use may move his finger off the button to cancel the press, which is standard and expected behaviour on iOS
UPDATE: Base on your comment to this answer perhaps you need to add the button to a specific point in your view heir achy. As in your storyboard views will be added as they are listed in that stroyboard starting from the top down, with the one on the bottom being the top view.
Try obviously making sure that views that you want to receive touches are not directly on top of each and that they do not overlap. Also try adding the programatically generated button above or below a specific view, rather than just making it the top subview in your main view which by the sounds of it isn't what you want.
As you're adding a button like this
[self.view addSubview:button];
it may be better to do it more like this
[self.view insertSubview:button aboveSubview:someOtherView]
To do this you'll probably need to hook up your "someOtherView" to an IBOutlet so you can reference it in your code. As it looks like you're most likely sticking your button over everything else, when you need to be more precise.

Make UIButton accessible (accessibility) in tableview header

I don't seem to be able to find anyone that has the same issue as me. All my tableview cells are perfectly fine for accessibility but my headers don't seem to. I have a button in my header view which just won't work for accessibility... Can anyone help me out with this?
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIButton *button = [[[UIButton alloc] initWithFrame: CGRectMake(282, 10, 28, 28)] autorelease];
button.isAccessibilityElement = TRUE;
button.titleLabel.text = #"Informatie";
[button addTarget:self action:#selector(infoButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:button];
}
I realise that I paraphrased this horribly. What I mean is, the button is working and all, just not for users that have assistive touch enabled on their phones. The phone isn't 'showing up' with the voice that helps the disabled users out.
And I do get the log error "AX ERROR: Could not find my mock parent, most likely I am stale."
You shouldn't set the button's title by modifying the label's text directly. Instead, use setTitle:forState:, e.g.:
[button setTitle:#"Informatie" forState:UIControlStateNormal];
Also, buttons are typically created with the class method buttonWithType: instead of alloc/initWithFrame:.

UIView/UIButton coordinates flipped

I have a coreplot project. The class of the view in viewcontroller has been changed to CPTGraphHostingView.
After creating the graph (this works fine),
I am adding a button as a subview , this launches a popover
the button shown is inverted. I have the same control in different view controllers and it works fine. The Popover also appears fine.
Here is the code that creates and adds the UIButton
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:#selector(monthSelection)
forControlEvents:UIControlEventTouchDown];
[button setTitle:#"Change Month" forState:UIControlStateNormal];
button.frame = CGRectMake(330, 650, 111, 40);
[self.view addSubview:button];
[here is a screenshot of whats happening. UIButton is suppose to show somewhere below the popover. What am i missing.
Do not add subviews to the graph hosting view. Instead, make other views siblings of the hosting view, i.e., add them as subviews of the same superview.

UIButton in UITableViewCell not responding in iOS 5x but responding in iOS 6

I have a button I'm adding in a UITableViewCell programmatically and it is behaving very strangely.
In iOS 6 it works exactly as expected. In iOS 5x it only responds to touch-down events and not touch-up-inside events. And even the touch down event only fires after you hold down for a second or two.
//Create UIButton
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
[button addTarget:self action:#selector(buttonTap) forControlEvents:UIControlEventTouchUpInside];
button.frame = CGRectMake(0, 0, 100, 100);
//Add to UITableViewCell
UITableViewCell *footerCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"FOOTER_CELL"] autorelease];
[footerCell.contentView addSubview:button];
//Also tried this with just [footerCell addSubview:button];
//Fire Action
- (void)buttonTap {
NSLog(#"Tap");
}
Pretty standard issue code. In fact I use this exact code to make buttons all over the place in my app and they all work, except in the table view. There's got to be something I'm not understanding about the structure of the cell.
Got it figured out. Long long ago I had put a UITapGestureRecognizer on the table for another reason. It was interfering with the button's functionality. Thanks guys. (and gals)

Resources