相关疑难解决方法(0)

dismissModalViewController并传回数据

我有两个视图控制器,firstViewControllersecondViewController.我正在使用此代码切换到我的secondViewController(我也传递一个字符串):

secondViewController *second = [[secondViewController alloc] initWithNibName:nil bundle:nil];

second.myString = @"This text is passed from firstViewController!";

second.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

[self presentModalViewController:second animated:YES];

[second release];
Run Code Online (Sandbox Code Playgroud)

然后我在secondViewController中使用此代码切换回firstViewController:

[self dismissModalViewControllerAnimated:YES];
Run Code Online (Sandbox Code Playgroud)

所有这一切都很好.我的问题是,如何将数据传递给firstViewController?我想从secondViewController传递一个不同的字符串到firstViewController.

iphone uiviewcontroller modalviewcontroller ios

84
推荐指数
2
解决办法
3万
查看次数

将数据传递回上一个viewcontroller

我正在尝试将数据传递回以前的viewController.

有谁知道如何将数据从ViewController B传递回ViewController A?所以我想要一个字符串'从'BIDAddTypeOfDealViewController转到BIDDCCreateViewController.用户编辑了viewController B,我想在ViewController A中返回已编辑的数据然后我使用它.

我正在使用此答案的"传递数据"部分.我的不同之处:第3点和第6点只是在弹出视图时提及,所以我将该代码放在viewWillDisappear中.我认为这是正确的吗?同样在Point 6,我没有使用nib进行初始化,因为它已经过时了.我正在使用故事板.而且我没有添加最后一行,因为我不相信我会推动它.按我的故事板上的按钮已经让我前进了.

我认为问题可能出现在BIDDCCreateViewController中,我有方法,但我无法运行它.要运行一个方法,它应该[自我方法].我无法做到这一点.那就是我猜的.

它编译并运行良好,没有任何记录,所以我不知道它是否有效.

更新:我无法获得'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 …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c uiviewcontroller ios

53
推荐指数
3
解决办法
6万
查看次数