-1

我可以通过将数据从表传递到其他表NSObject吗?

例子:

第一张表发送数据

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
     NSIndexPath *path = [self.tableView indexPathForSelectedRow];
     Data *g = [[Data alloc]init];
     [g setSelection1:(int)path.row];
}

NSLog测试选择1value = path.row;

当我使用第二个表时,我导入数据并分配它,但我在 selection1 中的值丢失了。

它始终为 0;

4

2 回答 2

0

尝试这个:

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{
    if ([segue.identifier isEqualToString:@"<YOUR_SEQUE_IDENTIFIER_GOES_HERE>"]) 
    {
        <YOUR_CONTROLLER> *destController =  (<YOUR_CONTROLLER> *)  
                                              segue.destinationViewController;

         NSIndexPath *path = [self.tableView indexPathForSelectedRow];
         Data *g = [[Data alloc] init]; 
         //if you would like to re-use this data source, I would suggest making this as a   
         //property within this class 

        [g setSelection1:(int)path.row];
        [destController setMyData:g];
    }
}

在第二个表中,声明一个属性:

@property (strong, nonatomic) Data *myData;
于 2013-10-06T11:17:37.493 回答
0

您的 Data 对象不会为您服务,因为您尚未将其传递给目标视图控制器。

你可以这样做

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
     NSIndexPath *path = [self.tableView indexPathForSelectedRow];
     Data *g = [[Data alloc]init];
     [g setSelection1:(int)path.row];

     MyTargetViewController *targetVC = segue.destinationViewController;
     [targetVC setData:g];
}

这里用你的实际目标视图控制器替换“MyTargetViewController”。

于 2013-10-06T11:11:12.847 回答