2013-02-02 40 views
0

當我們單擊一個單元格時,Iam有一個UItableview,我想要在單元格中獲取數據,並且必須分配給另一個控制器中的UIlabel並顯示它。就像我想爲所有人在表格中的單元格使用didselectRowAtIndex將tableview單元格數據分配給文本字段

在那個控制器我有一個UIlabel我想更新單元格數據。

任何一個可以幫助我是新來這個

(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *[email protected]"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]; 


} 
+0

我已經在這個問題上主演了2分鐘,但我無法掌握它的Xcode相關部分在哪裏。任何人都幫助我? – 2013-02-02 06:32:29

回答

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



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


} 
+0

在SecondView.m的didload方法的標籤文本中設置此passvalue字符串 – shivam

相關問題