2012-11-28 38 views
0

我面臨的問題是在DetailsOfPeopleViewController的標籤中顯示AddNotesViewController類的字符串的值。將值從一個類傳遞到其他類

我想要做的就是我們在1班的UITextView中輸入的內容,應顯示在另一班的UILabel中。

在文件AddNotesViewController.h

UITextView *txtView; 

    @property(nonatomic,retain)IBOutlet  UITextView *txtView; 

文件AddNotesViewController.m

@synthesize txtView; 

在此之後,當我在標籤欄的項目,點擊「保存」,那麼它應該保存在數據庫中, 其保存到數據庫並顯示該值,但它的值不會傳遞到

DetailsOfPeopleViewController

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{ 

     NSLog(@"Tabbar selected itm %d",item.tag); 

     switch (item.tag) { 
      case 0: 

     appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 


     NotesTable *crashNotInvolvingObj11 = (NotesTable *)[NSEntityDescription  
    insertNewObjectForEntityForName:@"NotesTable" inManagedObjectContext:[appDelegate managedObjectContext]]; 

     // CameraViewController *camera=[[CameraViewController alloc] init]; 
      crashNotInvolvingObj11.personNote=[NSString stringWithFormat:@"%@",txtView.text]; 

     DetailsOfPeopleViewController *detail=[DetailsOfPeopleViewController alloc]; 
     detail.testPersonNotesStr =[NSString stringWithFormat:@"%@",txtView.text]; 
     //(value of testPersonNotesStr is DISPLYING here...) 
     [appDelegate saveContext]; 
     [detail release]; 

     break; 
     .................. 

    } 
DetailsOfPeopleViewController.h

NSString *testPersonNotesStr; 
    UILabel *PersonNotesLbl; 

    @property(nonatomic,retain)IBOutlet UILabel *PersonNotesLbl; 
    @property(nonatomic,retain) NSString *testPersonNotesStr; 

DetailsOfPeopleViewController.m

 @synthesize PersonNotesLbl; 
     @synthesize testPersonNotesStr; 



     - (void)viewDidLoad 
     { 
     [super viewDidLoad]; 
      [PersonNotesLbl setText:testPersonNotesStr]; 

     NSLog(@"PERSON NOTE is........ %@",testPersonNotesStr); 
      //(value of testPersonNotesStr is NOT DISPLYING here.....) 

     } 

請指引我在哪裏,我在做的錯誤。

+0

可以請你告訴我,使用它的代碼你導航到DetailsOfPeopleViewController – Rajneesh071

回答

0

只是做在你的代碼幾件事,你會得到你的字符串

1: - >

Declair您DetailsOfPeopleViewController全球。

即,^ h

DetailsOfPeopleViewController *detail 

2: - >

在viewDidLoad中的alloc它

內存

detail=[[DetailsOfPeopleViewController alloc] init]; 

3: - >

只需申報您的字符串屬性複製

@property(nonatomic,copy) NSString *testPersonNotesStr; 

可以使用NSUserDefault

的SetValue

NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; 
[defaults setObject:[NSString stringWithFormat:@"%@",txtView.text]; forKey:@"testPersonNotesStr"]; 
[defaults synchronize]; 

的GetValue發送數據

testPersonNotesStr = [[NSUserDefaults standardUserDefaults] objectForKey:@"testPersonNotesStr"]; 
NSLog(@"PERSON NOTE is........ %@",testPersonNotesStr); 

按照我的回答i have NSString value in addViewController and i want to display this value in UILabel of DetailsViewController

+0

我只是做了烏爾的變化,但沒有結果亞爾.. – suvarna

+0

哪裏是推到DetailsOfPeopleViewController的代碼,意味着使用你要去喲DetailsOfPeopleViewController – Rajneesh071

+0

其中一些代碼其他類是那裏它的名字是PeopleHomeViewController其中包含表視圖,如果我們點擊tableView的行,然後它會去DetailsOfPeopleViewController。 – suvarna

0

你讓它成爲一個屬性,所以可能嘗試使用set方法。另外,在設置值之前,您需要初始化您的ViewControlelr。所以:

DetailsOfPeopleViewController *detail=[[DetailsOfPeopleViewController alloc] init]; 
[detail setTestPersonNotesStr:[NSString stringWithFormat:@"%@",txtView.text]]; 

而且我不明白,你居然顯示這個觀點,你必須要顯示該視圖的同一個實例,以實際看到的價值。

相關問題