【问题标题】:Custom UITableViewCell with UITextfield using Xcode 7使用 Xcode 7 自定义 UITableViewCell 和 UITextfield
【发布时间】:2015-11-20 12:29:42
【问题描述】:

我正在使用带有文本字段的自定义 UITableViewCell。当我按下右侧导航栏按钮(例如:完成等)时,我想访问每个文本字段的数据。我正在使用以下代码:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 2;
}

#pragma mark - UITableViewDelegate

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    CustomCell *cell = [[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil] objectAtIndex:0];
    if (cell == nil) {

    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.valueTextField.delegate = self;
    switch (indexPath.row) {
        case 0:
            cell.itemImageView.image = [UIImage imageNamed:@"user.png"];
            cell.valueTextField.placeholder = @"UserName";
            break;
        case 1:
            cell.itemImageView.image = [UIImage imageNamed:@"mail.png"];
            cell.valueTextField.placeholder = @"Email";

        default:
            break;
    }

【问题讨论】:

    标签: ios objective-c uitableview uitextfield


    【解决方案1】:

    试试这个

    -(IBAction)rightNavigationButton:(id)sender
    {
    
    NSInteger rowNumber = [projectListTable numberOfRowsInSection:0];
    
        NSIndexPath *indexpath = [NSIndexPath indexPathForRow:[projectListTable numberOfRowsInSection:0] inSection:0];
    
        for(int i = 0; i < rowNumber; i++)
        {
            CustomCell *cell = [projectListTable cellForRowAtIndexPath:[NSIndexPath indexPathForRow:rowNumber inSection:0]];
            NSString *str =  cell.valueTextField.text;
    
    //Do here what you want to do with textfield of each cell
        }
    }
    

    【讨论】:

      【解决方案2】:

      我解决了这样的问题:

       -(void)clickOnSend:(id)sender{
      
          NSInteger dynamicRows = [self.createUserTableView numberOfRowsInSection:0];
          for (int i=0; i<dynamicRows; i++) {
              NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
              UserProfileCell *cell = (UserProfileCell *)[self.createUserTableView cellForRowAtIndexPath:indexPath];
              DLog(@"cell textfield string :%@",cell.valueTextField.text);
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-05-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-04-29
        相关资源
        最近更新 更多