将值从一个类传递给另一个类 [英] passing the value from one class to other class
问题描述
我在 DetailsOfPeopleViewController的标签
中显示 AddNotesViewController
Class的字符串值时遇到问题。
I am facing the problem in displaying the value of string of AddNotesViewController
Class , in the Label of the DetailsOfPeopleViewController
.
我想做的就是我们在1个类的 UITextView
中输入的内容,应该显示在另一个类的UILabel
。
All i want to do is whatever we entered in the UITextView
of 1 class,should display in the UILabel
of another class.
在文件 AddNotesViewController.h
UITextView *txtView;
@property(nonatomic,retain)IBOutlet UITextView *txtView;
在文件 AddNotesViewController.m
@synthesize txtView;
此后,当我点击标签栏项保存时,它应保存在数据库中,
保存到数据库并显示值但是它没有将值传递给
After this when i click on the tab bar item "save" then it should save in the data base , its saving to database and displaying the value also but its not passing the value to
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;
..................
}
in 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..... )
}
请指导我在哪里犯错误。
Please guide me where am I doing the mistake.
推荐答案
在代码中做一些事情你会得到你的字符串
Just do few thing in your code you will get you string
1: - >
宣布你的 DetailsOfPeopleViewController 全局。
即。 in .h
DetailsOfPeopleViewController *detail
2: - >
在viewDidLoad中将其分配到内存中
in your viewDidLoad alloc it in memory
detail=[[DetailsOfPeopleViewController alloc] init];
3: - >
只需声明要复制的字符串属性
Just declare your string property to copy
@property(nonatomic,copy) NSString *testPersonNotesStr;
或
您可以使用NSUserDefault
You can send data using 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);
关注我的回答我在addViewController中有NSString值,我想在UILabel中显示这个值DetailsViewController
这篇关于将值从一个类传递给另一个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!