我可以看到一个textbox
、pickerview
和UIButton
(作为单选按钮工作)。在单击submit UIButton
时,应该在另一个具有tableView
的视图上显示用户输入的详细信息。我使用navigationController
在另一个视图上使用tableview
导航。导航工作正常,但是如何在view1
上显示view2
中输入的数据,在tableview中也是如此?以下是我的代码:.m
- (void) goToViewTwo
{
tableViewController *viewTwo = [[tableViewController alloc] initWithNibName:@"tableViewController" bundle:[NSBundle mainBundle]];
self.tabView = viewTwo;
[self.navigationController pushViewController:self.tabView animated:YES];
}
如何将数据分配给tabView?
编辑的包括.h of tableViwController
#import <UIKit/UIKit.h>
@interface tableViewController : UIViewController
@property(nonatomic,retain)NSString *name;
@property(nonatomic,retain)UILabel *lbl;
@property (strong, nonatomic) IBOutlet UILabel *textLabal;
@end
发布于 2013-01-09 05:56:09
就像你正在做的一样,除非在推下下一个视图控制器之前,在它上设置一个属性。例如,要在viewOne的viewTwo上显示文本,viewTwo将需要一个名为(类似于) textFromViewOne的字符串属性。
tableViewController *viewTwo = [[tableViewController alloc] initWithNibName:@"tableViewController" bundle:[NSBundle mainBundle]];
// assume this vc has an outlet to it's text field called viewOneTextField
viewTwo.textFromViewOne = viewOneTextField.text;
// not sure why you're saving a ref to this new vc, when do you use it?
self.tabView = viewTwo;
// you don't need it here
[self.navigationController pushViewController:viewTwo animated:YES];
现在,在第二个VC中,它可以包含UIControls来表示存储在其属性中的数据。继续文本示例..。
// assume you know how to create properties on the "tableViewController" class (not a great name, btw)
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// assume you have a label called label
label.text = self.textFromViewOne;
}
发布于 2013-01-09 05:51:32
您可以使用properties @property特性。
如视图2.h
@property(nonatomic,retain)NSString *name;
在视野2米
@synthesize name;
在你的视野中
- (void) goToViewTwo
{
tableViewController *viewTwo = [[tableViewController alloc] initWithNibName:@"tableViewController" bundle:[NSBundle mainBundle]];
self.tabView = viewTwo;
viewTwo.name=textbox.text;
[self.navigationController pushViewController:self.tabView animated:YES];
}
希望这有帮助..。
发布于 2013-01-09 05:50:07
您需要在tableViewController上设置一些属性。所以如果你是在传递一根绳子。tableViewController将在.h文件中包含以下内容。
@property (nonatomic, retain) NSString *mystring;
您也可以在.m文件中合成这个字符串。
@synthesize mystring;
然后您可以调用上面的代码
viewTwo.mystring = @"some value to pass through";
然后,通过调用tableViewController,您可以访问在self.mystring中传递的值。希望这对一些人有帮助。
https://stackoverflow.com/questions/14228960
复制相似问题