我在一个文件中有一个变量字符串,但我需要在另一个文件中使用它。这是一个面包店应用程序,它需要接受订单。 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];
}
-(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];
}
答案 0 :(得分:1)
在OrderViewController
中创建属性,然后将值分配给主视图控制器中的属性。我希望您知道如何创建属性,并且可以将值分配给事件中的属性...
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *__strong)indexPath {
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"detailViewController"bundle:nil];
detailViewController.item = [self.menu objectAtIndex:indexPath.row];
NSString *selectedItem = [menu objectAtIndex:indexPath.row];
// Here you need to assign the value to the property
detailViewController.theItemString = selectedItem;
[self.navigationController pushViewController:detailViewController animated:YES];
}