2

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

maggix
  • 3,268
  • 1
  • 22
  • 36
  • You can't just call [element getCellForTableView] because cells don't really exist until the tableview tries to display them. This is the presentation model that the UITableView uses to display data. – Eduardo Scoz Jul 27 '12 at 14:04

1 Answers1

2

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.

Amir
  • 9,091
  • 5
  • 34
  • 46
gregoltsov
  • 2,269
  • 1
  • 22
  • 37
  • Great answer @Gregory Goltsov. In general that is what I would do as well. – Eduardo Scoz Jul 27 '12 at 14:02
  • 1
    And it IS fully correct indeed. I added `` to header file and `self.quickDialogTableView.styleProvider = self;` in `viewDidLoad` method. Now I can customize my AccessoryView. By doing so, controllerAccessoryAction is not working anymore so I added [button addTarget:...] to the button itself. Any suggestion on how I could edit this question thread to improve it is welcome! – maggix Jul 27 '12 at 14:56
  • @maggix I've updated the question to reflect your comment. It helped me out (I was putting the delegate wire up in the init method). – Amir Apr 11 '13 at 12:49
  • 1
    Does anyone have an example of the implementation of this solution. I don't understand how to implement it. – Msmit1993 Oct 04 '13 at 07:01