更好的方法是在AddTaskViewController
上創建NSString*
屬性。你可以這樣說:
在AddTaskViewController.h
添加以下內容:
@property (nonatomic, strong) NSString* myLabelsText;
然後在AddTaskViewController.m
一定要添加這個在viewWillAppear
:
self.testlabel.text = self.myLabelsText;
現在假設你已經聲明瞭testLabel
和myLabelsText
適當,他們得到合成,你的視圖控制器將在適當的時間正確應用字符串,然後你的功能應該改爲:
- (IBAction)donebutton:(id)sender {
AddTaskViewController *addtask = [[AddTaskViewController alloc]initWithNibName:@"AddTask" bundle:nil];
// Set the value on your new NSString* property and let the view controller handle the rest
addTask.myLabelsText = self.zaman1.text;
// Don't you want to 'present' the view controller rather than 'dismiss' after having provided it with data?
[self dismissViewControllerAnimated:YES completion:nil];
}
你期望發生的?在您創建視圖控制器的那一刻,然後對它完全沒有任何影響。你是否想要'presentViewController:...'? – Tommy 2013-04-23 23:37:12
我想等於label.text – Salieh 2013-04-23 23:42:36
@Salieh:Tommy說得對,可能是你用'presentViewController'混淆了它。你究竟想達到什麼目的,你能否詳細說明一下? – 2013-04-24 00:01:44