How to access the UITableViewCell of a QuickDialog cell element? - ios

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.

Related

How to put the custom check box on the left side of UITableview with multiple selection?

I need to implement the uitableview selection with the design similar to the underseen design.
Please let me know how to accomplish this.
The best way for implementing checkbox is, you can take button and toggle the image.UIButton is a subclass of UIController,which has a selected property. You can use this property to toggle the on/off behaviour of a checkbox
Create a custom class of UITableview cell
Add number of buttons you wants on the cell
Give class name of UITableViewCell to the cell of tale view
Connect IB_Outlates of Buttons
In the delegate cellForRowAtIndexpath
myButton.tag = indexPath.row
[cell.myButton addTarget:self action:#selector(shippingBtnAction:) forControlEvents:UIControlEventTouchUpInside];
- (void)shippingBtnAction:(id)sender
{
UIButton* btn = (UIButton*)sender;
btn.selected = ! btn.selected;
if (btn.isSelected)
{
_isDefaultShipping = 1;
[self.shippingBtn setImage:[UIImage imageNamed:#"check"] forState:UIControlStateNormal];
}
else
{
_isDefaultShipping = 0;
[self.shippingBtn setImage:[UIImage imageNamed:#"uncheck"] forState:UIControlStateNormal];
}
}

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.

UIButton not highlighting when it is dynamically created

I have a dynamically created UIButton in my table's cellForRowAtIndexPath: method. It loads fine, and it can be selected, but it doesn't do the highlight animation when it is selected. I tried adding:
if(commandButton.isHighlighted), and that didn't trigger when selected. Here's how I load the cell:
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* CellIdentifier=#"CommandCell";
UITableViewCell* commandCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
UIButton* commandButton = [[UIButton alloc]initWithFrame:commandCell.frame];
[commandButton setTitle:#"Title" forState:UIControlStateNormal];
[commandCell.contentView addSubview:commandButton];
commandButton.backgroundColor = [UIColor blackColor];
return commandCell;
}
Whenever I click on it, commandButton is not highlighted...
EDIT: it was a stupid problem, I wasn't holding down my mouse for long enough. For those of you who have a similar problem, simply press down on the button for longer in the iOS simulator.
may this help you add the bellow code into ur code
if you want to so some image on tuchupinside then below code.
[commandButton setBackgroundImage:/*add you image using UIImage*/forState: UIControlStateHighlighted];
if you want simple (default background color when it appear in button on tuchupinside).
UIButton *buttonTap=[UIButton buttonWithType:UIButtonTypeRoundedRect];
and set the frame like this
buttonTap.frame=commandCell.frame;
//make some adjustment as per requied.
if u want some blur type effect(semi partial on selection )
Then you go for
UIButtonTypeCustom //type
The UIButton that you create in the following line
UIButton* commandButton = [[UIButton alloc]initWithFrame:commandCell.frame];
is a custom styled UIButton by default. For this button, you will have to set all the properties manually. What you want is this:
UIButton *commandButton = [UIButton buttonWithType:UIButtonTypeSystem];
[commandButton setFrame:cell.frame];
The UIButtonTypeSystem contains the style that you are looking for.
Hope this helps!
I don't know where are using this ? but still my suggestion is to give a tag to the button if you are adding it to the cell like :
UIButton* commandButton = [[UIButton alloc]initWithFrame:commandCell.frame];
[commandButton setTitle:#"Title" forState:UIControlStateNormal];
commandButton.tag = 1;
[commandCell addSubview:commandButton];
commandButton.backgroundColor = [UIColor blackColor];
and while accessing the same button ;
//you have to get the cell where button has been clicked
UIButton *button =(UIButton *)[cell viewWithTag:1];
and on this button you can use :
if(commandButton.isHighlighted)
Before you add button to cell view, try to add:
NSArray * views = [commandCell.contentView subviews];
for (UIView *object in views) {
[object removeFromSuperview ];
}
Because maybe u have multiple cells one on other, so the button is actually clicked is the "most bottom cell view" button.

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

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