[英]Error passing data between table view controller to detail view controller
I am getting an error while passing data from a table view controller to a detail view controller. 将数据从表视图控制器传递到详细信息视图控制器时遇到错误。 I am using a navigation controller along with it.
我正在使用导航控制器。
The error message is as follows: 错误消息如下:
use of undeclared identifier _wordLabel
使用未声明的标识符_wordLabel
This is the prepare for segue implementation in my table view controller (.m file). 这是我的表视图控制器(.m文件)中为segue实施准备的准备。
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"ShowWordDetails"]) {
//UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
wordDetailViewController *detailViewController = [segue destinationViewController];
NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow];
long row = [myIndexPath row];
detailViewController.wordDetailModel = @[_wordLabel[row], _meaningLabel[row]];
}
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
I have previously declared wordLabel
and meaningLabel
in the detail view controller as follows: 我以前在详细视图控制器中声明了
wordLabel
和meaningLabel
,如下所示:
@property (strong, nonatomic) IBOutlet UILabel *wordLabel;
@property (strong, nonatomic) IBOutlet UILabel *meaningLabel;
@property (strong, nonatomic) NSArray *wordDetailModel;
I have also declared it in viewDidLoad
method of detail view controller as follows: 我也在详细视图控制器的
viewDidLoad
方法中声明了它,如下所示:
-(void)viewDidLoad {
[super viewDidLoad];
_wordLabel.text = _wordDetailModel[0];
_meaningLabel.text = _wordDetailModel[1];
// Do any additional setup after loading the view.
}
_wordLabel
is private member of your detailViewController. _wordLabel
是detailViewController的私有成员。 You can't access it like you're trying to do in the first code quote. 您无法像在第一个代码引号中那样尝试访问它。 You need to call
detailViewController.wordLabel
instead. 您需要改为调用
detailViewController.wordLabel
。
first of all you can't use the array operator with a UILabel 首先,您不能将数组运算符与UILabel一起使用
_wordLabel[row]
second of all you have to define the _wordLabel[row] as an array in the TVC, that is separate from the label in the detailViewController 第二,您必须将_wordLabel [row]定义为TVC中的一个数组,该数组与detailViewController中的标签分开
I think you don't require wordDetailModel
as you can access UILabel
from TableViewController
as described below 我认为您不需要
wordDetailModel
因为您可以从TableViewController
访问UILabel
,如下所述
detailViewController.wordLabel.text = @"Word";
detailViewController.meaningLabel.text = @"Meaning";
_wordLabel
is UILabel
and it is private variable in DetailViewController
which can not be used directly from TableViewController
, you have to use it using property
. _wordLabel
是UILabel
,它是DetailViewController
中的私有变量,不能直接从TableViewController
中使用它,您必须使用property
使用它。 Plus _wordLabel
is not an array as already answered by @sha and @rockstarr 另外
_wordLabel
不是@sha和@rockstarr已经回答的数组
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.