Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting a UITableViewCell subview tag property
    primarykey
    data
    text
    <p>I have a UITableView, cells of which are customised in a NIB file so I can have a UILabel and UITextField.</p> <p>Therefore my cellForRowAtIndexPath looks like this:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { SectionCustomCell *cell = (SectionCustomCell *)[tableView dequeueReusableCellWithIdentifier: @"Section"]; NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SectionCustomCell" owner:self options:nil]; cell = [nib objectAtIndex:0]; // Set the label value [[cell inputLabel] setText:@"something"]; // Set the textfield tag property } </code></pre> <p>Therefore for a given section/row I am going to assign some text to the UILabel, defined as <strong>inputLabel</strong>, and have a UITextField, called <strong>inputTextField</strong> get some text from the user. </p> <p>My plan is to set the <strong>tag</strong> property of the UITextField so I can determine which field I am getting in the delegate <strong>textFieldDidEndEditing</strong>.</p> <p>Now my problem, if I put this code:</p> <pre><code> UITextField *textField = nil; for (UIView *oneView in cell.contentView.subviews) { if ([oneView isMemberOfClass:[UITextField class]]) textField = (UITextField *)oneView; } textField.tag = [indexPath row]; </code></pre> <p>the tag property is set correctly. (I know this from a NSLog statement). However if I do the following it is <strong>not</strong> set correctly. It is always 1 as defined in IB.</p> <pre><code> cell.inputTextField.tag = [indexPath row]; </code></pre> <p>but to me this <em>should</em> work. I am doing the same principle with the setting the labels text. Can someone help me to understand why it doesn't work?</p> <p>I'm new to iOS so go gentle :-)</p> <p>Thanks</p> <p>Mike</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload