Iphone 将文本从tableview发送到textfield

Iphone 将文本从tableview发送到textfield,iphone,text,uitableview,uitextfield,Iphone,Text,Uitableview,Uitextfield,我需要这样做:当用户从一个tableview中选择一行,将该行的文本从另一个tableview发送到一个textfield时。 例如,如果我从 我想在这里看到服务,靠近Partenaire类型: 我试过这个: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *selectedCell = [tableView ce

我需要这样做:当用户从一个tableview中选择一行,将该行的文本从另一个tableview发送到一个textfield时。 例如,如果我从

我想在这里看到服务,靠近Partenaire类型:

我试过这个:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
    NSString *cellText = selectedCell.textLabel.text;

    NSLog(@"%@",cellText);
 self.recherchePartenaireTableView.partenaire.text=cellText;
}
按下“确定”按钮时:

-(IBAction)OkButtonPressed:(id)sender{
    NSLog(@"BTN Ok");
    [self.recherchePartenaireTableView.tableviewrecherchepartenaire reloadData];
    [self.navigationController popViewControllerAnimated:YES];
}
但这是行不通的。有人能帮我吗?提前谢谢

在第一个图像的实现文件中

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {

        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];

        cell.backgroundColor = [UIColor clearColor];
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
        cell.backgroundView.opaque = NO;
        //cell.alpha = 0.65;

        cell.textLabel.backgroundColor = [UIColor clearColor];
        cell.textLabel.opaque = NO;
        cell.textLabel.textColor = [UIColor whiteColor];
        cell.textLabel.highlightedTextColor = [UIColor whiteColor];
        cell.textLabel.font = [UIFont boldSystemFontOfSize:18];

        cell.detailTextLabel.backgroundColor = [UIColor clearColor];
        cell.detailTextLabel.opaque = NO;
        cell.detailTextLabel.textColor = [UIColor whiteColor];
        cell.detailTextLabel.highlightedTextColor = [UIColor whiteColor];
        cell.detailTextLabel.font = [UIFont systemFontOfSize:14];
    }

    // Set up the cell...
    [[cell textLabel] setText: [typePartenaireArray objectAtIndex:indexPath.row]] ;

    return cell;
}
**在第二个映像的实现文件中**

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        static NSString *CellIdentifier = @"Cell";

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {

            cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];

            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.backgroundColor = [UIColor clearColor];
            cell.selectionStyle = UITableViewCellSelectionStyleGray;
            cell.backgroundView.opaque = NO;
            //cell.alpha = 0.65;

            cell.textLabel.backgroundColor = [UIColor clearColor];
            cell.textLabel.opaque = NO;
            cell.textLabel.textColor = [UIColor whiteColor];
            cell.textLabel.highlightedTextColor = [UIColor whiteColor];
            cell.textLabel.font = [UIFont boldSystemFontOfSize:18];

            cell.detailTextLabel.backgroundColor = [UIColor clearColor];
            cell.detailTextLabel.opaque = NO;
            cell.detailTextLabel.textColor = [UIColor whiteColor];
            cell.detailTextLabel.highlightedTextColor = [UIColor whiteColor];
            cell.detailTextLabel.font = [UIFont systemFontOfSize:14];

            if(indexPath.row==0)
            {
                partenaire=[[UITextField alloc] init];
                partenaire.frame = CGRectMake(200,10,80,50);
                partenaire.textColor=[UIColor grayColor];
                partenaire.text=@"Tous";     
                [partenaire setKeyboardAppearance:NO];
                [cell.contentView addSubview:partenaire];

            }

        }

        // Set up the cell...
        [[cell textLabel] setText: [arraytableview objectAtIndex:indexPath.row]] ;

        return cell;


}

您必须将文本插入位置1的数组arraytableview(数组从0开始)。确保将其声明为NSMutableArray,否则无法更改它

因此,您必须在OK方法中执行:
[arraytableview insertObject:cellText-atIndex:1]
。为此,您可能需要引入一个保存当前所选文本的变量,以将其从所选方法“传输”到OK方法

或者您只需将其添加到
-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
,但它会立即添加文本,而无需按OK。这取决于你想要什么

我希望现在清楚了

使用多行、文本字段等定义UITableViewCell的代码:

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {

        imageView = [[UIImageView alloc] initWithFrame: CGRectZero];
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        [self.contentView addSubview: imageView];

        titleLabel = [[UILabel alloc] initWithFrame: CGRectZero];
        [titleLabel setFont:[UIFont systemFontOfSize:14.0]];
        [titleLabel setTextColor:[UIColor blackColor]];
        [titleLabel setHighlightedTextColor:[UIColor darkGrayColor]];
        [titleLabel setLineBreakMode: UILineBreakModeWordWrap];
        titleLabel.numberOfLines = 2;

        [self.contentView addSubview: titleLabel];

        description = [[UITextField alloc] initWithFrame: CGRectZero];
        [description setFont:[UIFont systemFontOfSize:12.0]];
        [description setTextColor:[UIColor darkGrayColor]];
        [description setHighlightedTextColor:[UIColor darkGrayColor]];
        [self.contentView addSubview: description];


    }
    return self;
}

    -(void) layoutSubviews {
        [super layoutSubviews];
        //  D_IN;   
        [imageView setFrame:CGRectMake(8.0, 10.0, 20.0, 20.0)];
        [titleLabel setFrame:CGRectMake(40.0, 1.0, 250.0, 40.0)]; //two lines
        [description setFrame:CGRectMake(40.0, 37.0, 250.0, 3.0)];//not used

        //  D_OUT;  
}
为每个新组件指定起始x和y时,请确保布局正确,否则将看不到任何内容

那就用

 titleLabel.text = 


重写第二个UITableView的init方法以接受额外的参数(在您的情况下,是当前UITableView中所选单元格的文本)。在配置单元格的第二个UITableView中,使用刚刚从第二个tableView对象被alloc inited的上一个tableView中收到的参数设置单元格文本。

您必须将单元格文本添加到所检索表的数据结构中。是你干的吗?什么意思?您可以更明确一点吗?您是否尝试过UITableViewCell*selectedCell=[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:0]。。。?。。什么打印NSLog语句?来自didSelectRowAtIndexPath的NSLog打印来自第一幅图像的文本..我没有试过你说的,我不知道如何使用你想要的?您是否在第二个表格的第一行文本字段中打印了,该字段是从第一个表格行中选择的?您不太了解我要做的事情…我必须将TypePartNaire中的文本放在第二个表格视图中,该视图包含arraytableview和一些文本文件…所以我不能像您所说的那样做,因为您是对的,我从错误的文本中复制-我编辑了上面的答案这也不正确,因为textfield中的文本不在ArrayTableView中在您的问题中,您写道:我需要这样做:当用户从tableview中选择一行时,将该行中的文本从其他tableview发送到textfield。例如,如果我从“在此处输入图像描述”中选择服务。。。我想在这里看到服务,靠近类型de Partenaire:-所以如果你想看到文本“Services”旁边的“Type de Partenaire”,这就是你要做的。或者请解释一下,以便我能更好地理解您想要的内容……我将文本字段添加到某一行,如下所示:if(indexPath.row==0){partenaire=[[UITextField alloc]init];partenaire.frame=CGRectMake(200,10,80,50);partenaire.textColor=[UIColor grayColor];partenaire.text=@“Tous”;[partenaire设置键盘外观:否];[cell.contentView addSubview:partenaire];}
description.text =