数据从自定义表视图控制器传递到视图控制器

时间:2017-07-11 11:29:15

标签: ios objective-c uitableview

我制作了一个自定义表视图控制器,其中有一些标签从API响应中获取值。一些值显示在自定义表视图中,我有另一个名为Detail vc的视图控制器,我想在其中显示我从API获取的数据的详细信息。我通过segue将数据从自定义表传递到详细信息vc但我面临错误,我不知道问题出在哪里。我使用相同的方法将数据从一个vc传递到另一个vc,它工作正常,但我不知道它为什么不在这里工作。错误是,

  

2017-07-11 15:57:22.177 PK.House [9403:604414] ***由于未捕获的异常终止应用程序' NSInvalidArgumentException',原因:' - [StringData length] :无法识别的选择器发送到实例0x60800012b400'

我的segue代码是,

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"ShowDetail"]) {
        //Do something
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        ShowViewController *destViewController = segue.destinationViewController;
         destViewController.tites = [_Title objectAtIndex:indexPath.row];
         destViewController.prce = [_Price objectAtIndex:indexPath.row];
         destViewController.ara = [_LandArea objectAtIndex:indexPath.row];
         destViewController.phon = [_Phone objectAtIndex:indexPath.row];
        // destViewController.citi = [_City objectAtIndex:indexPath.row];
         destViewController.loc = [_location objectAtIndex:indexPath.row];
        // destViewController.tye = [_type objectAtIndex:indexPath.row];
        // destViewController.Idss = [_Id objectAtIndex:indexPath.row];
         destViewController.nam = [_name objectAtIndex:indexPath.row];
         destViewController.emal = [_email objectAtIndex:indexPath.row];
         destViewController.roomss = [_rooms objectAtIndex:indexPath.row];
         destViewController.wash = [_washroom objectAtIndex:indexPath.row];
         destViewController.flloors = [_floor objectAtIndex:indexPath.row];
         //destViewController.stat = [_status objectAtIndex:indexPath.row];
         destViewController.descrp = [_descrip objectAtIndex:indexPath.row];
        // destViewController.countryy = [_country objectAtIndex:indexPath.row];

    }
}

详情vc是,

- (void)viewDidLoad {
    [super viewDidLoad];

    UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
                                   initWithTitle:@"BACK"
                                   style:UIBarButtonItemStyleDone
                                   target:self
                                   action:@selector(backBtnClicked)];
    self.navigationItem.leftBarButtonItem = backButton;
    backButton.tintColor=[UIColor whiteColor];

   /* int x=0;
    NSArray *image=[[NSArray alloc]initWithObjects:@"city.png",@"area.png",@"twitter.png", nil];
    for (int i=0; i<image.count; i++)
    {
        UIImageView *img=[[UIImageView alloc]initWithFrame:CGRectMake(x, 0,[[UIScreen mainScreen] bounds].size.width,[[UIScreen mainScreen] bounds].size.height)];
        img.image=[UIImage imageNamed:[image objectAtIndex:i]];
        x=x+[[UIScreen mainScreen] bounds].size.width;

    }*/

    self.Title.text = _tites;
    self.name.text = _nam;
    self.email.text = _emal;
    self.status.text = _stat;
    self.type.text = _tye;
    self.phone.text = _phon;
    self.rooms.text = _roomss;
    self.floor.text = _flloors;
    self.washroom.text = _wash;
    self.location.text = _loc;
    self.Descrip.text = _descrp;
    self.city.text = _citi;
    self.country.text = _countryy;
    self.propid.text = Idss;


    // Do any additional setup after loading the view.
}

2 个答案:

答案 0 :(得分:0)

看起来你正在使用objectAtIndex方法的一些数据只是一个字符串而不是一个数组。可能是以下一项或全部:_Title_Price_name等。

答案 1 :(得分:0)

在您的代码中

self.Title.text = _tites;
self.name.text = _nam;
self.email.text = _emal;
self.status.text = _stat;
self.type.text = _tye;
self.phone.text = _phon;
self.rooms.text = _roomss;
self.floor.text = _flloors;
self.washroom.text = _wash;
self.location.text = _loc;
self.Descrip.text = _descrp;
self.city.text = _citi;
self.country.text = _countryy;
self.propid.text = Idss;

您分配给.text的其中一个变量是NSArray。

仔细检查调用objectAtIndex:后得到的值实际上是字符串。我的猜测是其中一个是数组。