I’m trying to pass the storeId to another viewController using segue, however, there seems to be a delay when passing data? Data is "nil" at first, I have to tap it again in order it to pass the correct data.
Here is my code
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.passStoreData = self.storeList [indexPath.row];
self.passStoreId = [self.storeList [indexPath.row] valueForKey:@"storeId"];
self.passStoreName = [self.storeList [indexPath.row] valueForKey:@"storeName"];
NSString *store = [NSString stringWithFormat:@"%@ : %@", self.passStoreId, self.passStoreName];
[self.storeButton setTitle:[NSString stringWithFormat:@"%@", store] forState:UIControlStateNormal];
storeTable.hidden = YES;
[self performSegueWithIdentifier:@"showOrder" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
OrderListViewController *orderListVc = [segue destinationViewController];
orderListVc.theStoreId = self.passStoreData;
}
What can I do to avoid the delay in passing the data using segue? Thank you.
2
Answers
After trying and researching. I found the answer to this.
I used
dispatch_async(dispatch_get_main_queue()
to run it on main thread and the passing of data through segue was not delayed. Thank youBy the time you call
[segue destinationViewController]
, theOrderListViewController
is loaded and ready to use. So any code inviewDidLoad
will already have been called, way before you settheStoreId
.Move your view setup code to
viewWillAppear:
and it should work.