简体   繁体   English

在表视图控制器到详细视图控制器之间传递数据时出错

[英]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: 我以前在详细视图控制器中声明了wordLabelmeaningLabel ,如下所示:

@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 . _wordLabelUILabel ,它是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.

相关问题 将数据从表视图控制器传递到详细视图控制器 - Passing data from a Table View Controller to a Detail View Controller 在表视图控制器与其详细视图控制器之间传递对象,并收到NSInvalidArgumentException错误 - Passing an Object between Table View Controller and it's Detail View Controller, getting NSInvalidArgumentException error 将 Firebase 数据从一个视图控制器传递到详细视图控制器 - Passing Firebase Data from one view controller to detail view controller 使用Parse.com在表视图控制器和详细视图控制器之间传递数据 - Pass data between table view controller to detail view controller using Parse.com 将数据传递到表视图控制器 - Passing data to table view controller 将模型数据作为iOS中的明细控制器传递到标签栏视图控制器 - Passing model data to tab bar view controller as a detail controller in iOS 在自定义视图和视图控制器之间传递数据 - Passing data between custom view and view controller 将数据从表视图单元格传递给新的视图控制器错误 - Passing data from table view cell to new view controller error 将数据从表视图传递到视图控制器 - Passing data from table view to view controller 将数据从视图控制器传递到第一个详细信息控制器,然后传递到第二个详细信息控制器 - Passing Data from a View Controller to a First Detail Controller and then to a Second Detail Controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM