使用didselectRowAtIndex将tableview单元格数据分配给textfield

时间:2013-02-02 06:24:48

标签: iphone uitableview xcode4.2

当我们点击一​​个单元格时,我想要获取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 个答案:

答案 0 :(得分:0)

在第二个视图控制器中创建UITextField的属性,如:

.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]; 



}

答案 1 :(得分:0)

试试这个:

在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];


}
相关问题