2013-08-19 45 views
0

我有一個viewControllertextView和一個label我想在的TextView上的文字傳遞給標籤傳遞的TextView標記-iPhone

首先

.m 

textView= [[UITextView alloc] initwithFrame... 

/A secondviewController /改變視圖和發送的TextView標記

-(void) gotoSecond:(id) sender{ 
Second *sec = [[Second alloc]initWithNibName: @"Second" bundle:nil]; 
[sec.note setText:textView.text] 
[self presentViewController:sec animated: YES completion:NULL]; 

} 

Second .h 

//附着在筆尖

@propery (nonatomic, strong) IBOutlet UILabel *note; 
+0

那麼會發生什麼?它是否給出錯誤?還是文字沒有設置?是sec.note'! nil',當你嘗試設置文本? –

+0

聽起來像一個破損的綁定或類似的問題。除非你不使用XIB,而是以編程方式初始化'UILabel'。那麼你將不得不看到你早點初始化它。 –

+0

好吧,所以我不能使用xib與標籤?它不會返回一個錯誤,只是標籤文本沒有被設置 – user2645586

回答

0

使用此:

在viewController.m

-(void) gotoSecond{ 
secondViewController *sec = [[secondViewController alloc]initWithNibName: @"Second" bundle:nil]; 
[sec.passedText setText:textView.text] 
[self presentViewController:sec animated: YES completion:NULL]; 

} 

在secondViewController.h

@property(nonatomic, strong)NSString *passedText; 

在secondViewController.m

-(void)viewDidLoad 
{ 
    self.note.text = passedText; 
} 
+0

謝謝!與輕微編輯 – user2645586

+0

@ user2645586 upvote它.. –

0

使用此:

-(void) gotoSecond:(id) sender{ 
    Second *sec = [[Second alloc]initWithNibName: @"Second" bundle:nil]; 
    [self presentViewController:sec animated: YES completion:^(){ 
     [sec.note setText:textView.text]; 
    }]; 
}