Make UIButton accessible (accessibility) in tableview header - ios

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:.

Related

how to set the action for accessoryView except the didselectrow at index path in iOS

Actually i am create action for custom accessory view uibutton in cellForRowAtIndexPath
UIButton *addButton = [UIButton buttonWithType:UIButtonTypeCustom];
addButton.frame = CGRectMake(0, 0, 25, 25);
[addButton setBackgroundImage:[UIImage imageNamed:#"Unchecked.png"] forState:UIControlStateNormal];
[addButton addTarget:self action:#selector(checkButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
- (void)checkButtonTapped:(id)sender event:(id)event{
[self tableView: self.grouptableview accessoryButtonTappedForRowWithIndexPath: indexPath];
}
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
NSLog(#"indexPath.row: %ld",(long)indexPath.row);
}
its working fine when i didn't use the didSelectRowAtIndexPath method.
Problem is: some times the click event in accessory view not recognize instead of it triggers the didSelectRowAtIndexPath function.
How to i specify the user interaction for accessory view and differentiate from the didSelectRowAtIndexPath in tableview ?
please help me to solve this. Thanks..
It looks like design Problem.
(0, 0, 25, 25)
get a new image from your designer with more transparent area towards top, down, left and right.
It will solve your problem.
Thanks.
Your problem is the height and width of your uibutton which you are specifying in your program. function CGRectMake defines the position and the area your button covers which is small and enables a user to perform its functions like touchupinside touchupoutside etc.
Sometimes user touch over a button but at that time cell gets focus and executes accordingly because of uibutton cover area over it.

UITableView Add FooterView Button Sometimes Tap Doesn't Perform Action

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).

Custom UIButton No Longer Works After Changing UIView to UIViewController

This code worked in a UIView container, but after changing that container to a UIViewController, the code no longer works:
-(void)viewDidLoad
{
[super viewDidLoad];
[self.view setUserInteractionEnabled:YES];
// set button
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(60, 30, 220, 220);
[button setImage:self.obj.img forState:UIControlStateNormal];
[button addTarget:self action:#selector(selected:) forControlEvents:UIControlEventTouchUpInside];
[button setUserInteractionEnabled:YES];
[self.view addSubview:button];
}
-(void) selected:(UIButton *) button // also tried (id) sender
{
NSLog(#“Button Selected“);
}
These containers are created programmatically (dynamically), from web services, so I cannot use Storyboard. The reason for changing to a UIViewController is that I need a segue to another screen. Also, these containers are placed in a UIScrollView.
Everything else is working properly, except the selector.
Setting the userInteraction wasn't necessary earlier, but I've gone ahead and tried that in different configurations. I've added this to the scrollview, the viewController, and the button, just for good measure.
I even tried some online tutorials for programmatically creating UIButtons in UIViewControllers and was able to do that just fine. Not sure what the issue is here. Thanks.

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)

How to access the UITableViewCell of a QuickDialog cell element?

I am trying to access the properties of the UITableViewCell of a QuickDialog form.
More specifically, I am trying to access the accessoryView property of a QEntryElement (QDateTimeInlineElement), which is "hidden" in the property list of the object I create.
I am trying to access the cell using
UITableViewCell *thisCell = [dateelement getCellForTableView:self.quickDialogTableView controller:self];
But for some reasons nothing is displayed. I am trying to insert a UIButton in it, like this:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setTitle:#"=" forState:UIControlStateNormal];
button.frame = CGRectMake(0, 0, 24, 24);
and then
thisCell.accessoryView = button;
Am I accessing the property in a wrong way or maybe the button is not created at all? No errors are displayed, but the accessoryView is empty.
Thank you in advance
This issue looks very close to what you are asking. Basically, you first have to provide your own QuickDialogStyleProvider, implementing the cell:willAppearForElement:atIndexPath: method the way escoz suggests there:
Once you get the call in the provider method, you have full control of the cell. You can just check if the cell is of type QEntryTableViewCell, and if it is, cast to that type and change the color/font of the textField property. A nice side effect is that this will also change the color for all subclasses, like the radio button, date/time fields, etc..
So, in your case you'd do something like
- (void)viewDidLoad
{
self.quickDialogTableView.styleProvider = self;
}
- (void)cell:(UITableViewCell *)cell willAppearForElement:(QElement *)element atIndexPath:(NSIndexPath *)indexPath
{
if([cell isKindOfClass:[QDateTimeInlineElement class]])
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setTitle:#"=" forState:UIControlStateNormal];
button.frame = CGRectMake(0, 0, 24, 24);
cell.accessoryView = button;
}
}
Sorry if it's not fully correct, I'm away from Xcode at the moment.

Resources