Accessing UITextField in a custom UITableViewCell

后端 未结 6 1616
无人及你
无人及你 2020-12-03 08:38

I have a UITableViewCell (with associated UITableViewCell sub class, .m & .h) created in IB which contains a UITextField. This UITextField is connected up to an IBOutlet

6条回答
  •  不知归路
    2020-12-03 08:44

    This tutorial was helpful to me. You can reference whatever object you need through the tag.

    In the Storyboard drag on a UIImageView or UITextField etc. and set the tag to 100 (whatever you want) then in your - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath use the tag to reference it.

    Here's something you could do, just remember to set the tags in the storyboard:

     - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
     {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    // Configure the cell...
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    
     UITextField *tField = (UITextField *)[cell viewWithTag:100];
    
    return cell;
     }
    

提交回复
热议问题