Table Cell SubView Iteration Not Finding TextField

前端 未结 4 464
面向向阳花
面向向阳花 2021-01-17 07:03

I\'ve created a table where each cell holds both a text label and a text field. I\'m adding the textfields as such [cell addSubview:passwordField]; and from a v

4条回答
  •  醉话见心
    2021-01-17 07:44

    Instead of UIView* subView = [[cell.contentView subviews]lastObject]; you can try to find it as:

    for(UIView *view in [cell subviews])
    {
      if([view isKindOfClass:[UITextfield class]]){
        // view is the reference to your textfield
      }
    }
    

    That way you can add other UIViews as subviews and still get the reference of the textfield without having to keep track of its subview index.

提交回复
热议问题