【问题标题】:assign tableview cell data to textfield using didselectRowAtIndex使用 didselectRowAtIndex 将表格视图单元格数据分配给文本字段
【发布时间】:2013-02-02 06:24:48
【问题描述】:

当我们单击一个单元格时,我有一个 UItableview 我想获取单元格中的数据,并且必须分配给另一个控制器中的 UIlabel 并显示它。就像我想对 tableview 中的所有单元格一样

在那个控制器中,我有一个 UIlabel,我想将单元格数据更新为那个。

谁能帮我这个新手

(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellidentifier=@"cell";
    UITableViewCell *cell=[tableview dequeueReusableCellWithIdentifier:cellidentifier];
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellidentifier];    
           }
    cell.textLabel.text=[array objectAtIndex:indexPath.row];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    Companydetails *details1= [[Companydetails alloc] initWithNibName:@"Companydetails" bundle:nil];
    details1.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:details1 animated:NO];
    [details1 release]; 
    UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];


}

【问题讨论】:

  • 我已经关注这个问题 2 分钟了,但我无法理解它与 Xcode 相关的部分在哪里。有人帮帮我吗?

标签: iphone uitableview xcode4.2


【解决方案1】:

在你的第二个视图控制器中创建一个 UITextField Like 的属性:

.h file
@property (nonatomic,retain) UITextField *txtField;

.m file
@synthesize txtField;

现在在您当前的类中,您希望从该类中显示第二个视图控制器的 UITextField 的视图控制器设置值。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
    Companydetails *details1= [[Companydetails alloc] initWithNibName:@"Companydetails" bundle:nil];
    details1.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    details1.txtField.text = cell.textLabel.text. 
    [self presentModalViewController:details1 animated:NO];
    [details1 release]; 



}

【讨论】:

    【解决方案2】:

    试试这个:

    在SeconView.h中

    NSString *passValue;
    @property(nonatomic,retain) NSString *passValue;
    

    在 SecondView.m 中

    @synthesize passValue;
    

    在 FirstView.m 中

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
    
        Companydetails *details1= [[Companydetails alloc] initWithNibName:@"Companydetails" bundle:nil];
        details1.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    details1.passValue=[array objectAtIndex:indexPath.row];
        [self presentModalViewController:details1 animated:YES];
    
    
    }
    

    【讨论】:

    • 在 SecondView.m 的 didload 方法中的标签文本上设置这个密码字符串
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多