データを前のviewControllerに戻そうとしています。
ViewController B から ViewController A にデータを戻す方法を知っている人はいますか? したがって、文字列を BIDAddTypeOfDealViewController から BIDDCCreateViewController に移動する必要があります。ユーザーがviewController Bを編集し、編集したデータをViewController Aに戻し、そこで使用します。
この回答の「データを戻す」セクションを使用しています。私の違い: ポイント 3 と 6 は、ビューがいつポップされるかについて言及しているだけなので、そのコードを viewWillDisappear に入れました。それは正しいと思いますか?また、ポイント 6 では、ペン先が古いため、ペン先で初期化しませんでした。ストーリーボードを使用しています。そして、プッシュする必要があるとは思わないので、最後の行を追加しませんでした。ストーリーボードのボタンを押すと、すでに先に進みます。
BIDDCCreateViewController で問題が発生する可能性があると思います。メソッドはありますが、実行できません。メソッドを実行するには、[self method] に移動する必要があります。私にはそれができません。まあ、それは私が推測していることです。
何もログに記録されないだけでコンパイルして正常に実行されるため、機能するかどうかはわかりません。
更新:「sendDataToA」メソッドを実行できません。
#import <UIKit/UIKit.h>
#import "BIDAddTypeOfDealViewController.h"
@interface BIDDCCreateViewController : UIViewController
@property (strong, nonatomic) NSString *placeId;
- (IBAction)gotoBViewController:(id)sender;
@end
#import "BIDDCCreateViewController.h"
#import "BIDAddTypeOfDealViewController.h"
@implementation BIDDCCreateViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSLog(@"SUCCESSFULLY PASSED PLACE ID: %@", self.placeId);
}
-(void)sendDataToA:(NSString *)myStringData
{
NSLog(@"Inside sendDataToA");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Your string Data Showing" message:myStringData delegate:self cancelButtonTitle:@"Ok " otherButtonTitles:nil];
[alert show];
}
- (IBAction)gotoBViewController:(id)sender {
NSLog(@"pressed");
BIDAddTypeOfDealViewController *bidAddType = [[BIDAddTypeOfDealViewController alloc]init];
bidAddType.delegate = self;
}
@end
@protocol senddataProtocol <NSObject>
-(void)sendDataToA:(NSString *)myStringData;
@end
#import <UIKit/UIKit.h>
@interface BIDAddTypeOfDealViewController : UIViewController <UITextFieldDelegate>//Using this delegate for data a user inputs
@property(nonatomic,assign)id delegate;
//other textfield outlets not relevant
- (IBAction)chooseDiscountDeal:(id)sender;
@end
#import "BIDAddTypeOfDealViewController.h"
@interface BIDAddTypeOfDealViewController ()
@end
@implementation BIDAddTypeOfDealViewController
@synthesize delegate;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
-(void)viewWillDisappear:(BOOL)animated
{
[delegate sendDataToA:@"Apple"];
}
@end