Kana Kana - 1 year ago 76
iOS Question

Pass data UItable to UItable Via NSObject

Can I pass the data from table to other table via



First table send data

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

test selecttion1
value = path.row;

When I use second table I import the data and alloc it but my value in selection1 is lost.

It is always 0;

Answer Source

Try this:

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

         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];

In your second table, declare a property:

@property (strong, nonatomic) Data *myData;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download