I have a variable string in one file, but I need to use it in another. It is a bakery application, and it needs to take orders. There is a tableview in the MasterViewController and the bakery needs to know what was tapped in the first place. Is there a way to do this?
Here is my code:
MasterViewController
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *__strong)indexPath {
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"detailViewController"bundle:nil];
detailViewController.item = [self.menu objectAtIndex:indexPath.row];
[self.navigationController pushViewController:detailViewController animated:YES];
NSString *selectedItem = [menu objectAtIndex:indexPath.row];
}
OrderViewController
-(IBAction)orderButtonTapped:(id)sender {
int whereString = [wherePicker selectedRowInComponent:1];
NSString *mobileString = [mobileField text];
int amountNumber = [amountPicker selectedRowInComponent:1];
NSString *specialString = [specialField text];
NSString *itemString = /*get the string from file here*/
NSString *orderString = [[NSString alloc] initWithFormat:@"I would like %d %@ delivered to %@. My mobile number is %@. %@", amountNumber, itemString, whereString, mobileString, specialString];
}
Create a property in
OrderViewControllerand then assign the value to the property in master view controller. I hope you know how to create a property, and you can assign the value to the property inside your event…