将Array值传递给另一个viewcontroller,并在标签上显示值,并在Button click上更改文本

时间:2016-04-08 10:41:42

标签: ios textview nsarray tableview uilocalnotification

`I am develop `IOS` App. Store data on Nsmutablearray using class object.and show the data on tableview and pass the data on next viewcontroller.On next viewcontroller get value for using class object app crash error msg is reason`: '-[ReligiousStatus objectAtIndex:]: unrecognized selector sent to instance 0x7b9f0100'

并且按钮单击更改textview字符串值。将显示相同的错误

请提供任何帮助,并提前致谢

//Code

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ViewStatusViewController *view = [[UIStoryboard storyboardWithName:@"Main" bundle:nil]instantiateViewControllerWithIdentifier:@"viewStatus"];

    view.array = [self.Data objectAtIndex:indexPath.row]; //pass data to another view controller

    [self.navigationController pushViewController:view animated:YES];
}

//get value from second viewcontroller
 ReligiousStatus *sts = [_array objectAtIndex:0]; //Class name ReligiousStatus
    _textView.text = sts.status;

//button click change the textView value 

- (IBAction)next:(id)sender {
    NSInteger increment;
    increment++;

 //   NSMutableArray *arr    = [NSMutableArray arrayWithObject:_status.status];

    ReligiousStatus *sts = (ReligiousStatus *)[_array objectAtIndex:increment];
        _textView.text = [NSString stringWithFormat:@"%@",sts.status];

    if (increment> sts.status.length) {


        _textView.text = [NSString stringWithFormat:@"%@",sts.status];
    }

1 个答案:

答案 0 :(得分:0)

确保

[self.Data objectAtIndex:indexPath.row]; 

是数组并包含对象

在使用之前检查它是否包含对象

if(array.count) {

}