「setTimeViewController」というviewControllerが1つあります。「setEventViewController」という別のビューコントローラがあります。ユーザーはsetTimeViewControllerのテーブルの行をタップし、UIPickerViewと保存ボタンのみを含むsetEventViewControllerに送信されます。ユーザーが保存ボタンをタップすると、setTimeViewControllerに戻ります。
そのピッカーでsetEventViewControllerから選択された値に、setTimeViewControllerからアクセスできるようにしたいのですが、(null)を返しています。NSString *theVariableを.hsetEventViewControllerで宣言しました。これは、他のView Controllerから取得しようとしている変数であり、そのプロパティを保持していますが、まだnullです。
setEventViewControllerのviewDidDisappearからテスト(変数NSLog)を実行して、ビューが消えるときにnullかどうかを確認しましたが、正常に機能します。
これが私のコードです。誰かが私を助けてくれるなら、私は永遠に感謝します。ありがとうございました!
setEventViewController.m
- (void)pickerView:(UIPickerView *)pickerView
didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
theVariable= [currentItemsInPicker objectAtIndex:row];
//[theVariable retain]; //Tried this as well but did not work
}
-(IBAction) Save
{
//simply dismisses the view controller back to setTimeViewController. Have also tried to set another NSString equal to theVariable but this did not work.
[self.navigationController popViewControllerAnimated:YES];
}
setTimeViewController
-(void) retrieveTheEvent
{
setEventViewController *eventViewController= [[setEventViewController alloc] init];
NSString *testString= eventViewController.theVariable;
NSLog (@"the event is %@", testString); //shows null
}