ios - 使用模态 Segue 将数据传递到下一个 View Controller

标签 ios storyboard uistoryboardsegue

我尝试在 Storyboard 中使用模态转场从 didSelectRowAtIndexPath 推送用户数据并将其发送到下一个 View Controller 。

这是我的代码:

在我的头文件中:

@interface ListNearby : UIViewController<UITableViewDataSource,UITableViewDelegate,CLLocationManagerDelegate,UINavigationControllerDelegate,UINavigationBarDelegate>

{
   @public
   UserDetails *UD;
}

还有我的 .m 文件:

ResultNearbyList *cell = (ResultNearbyList *) [tableView cellForRowAtIndexPath:indexPath];

self.userFullNameString = cell.userFullName.text;

NSLog(@"FulluserName NextVC = %@",self.userFullNameString);

[self performSegueWithIdentifier:@"sendUserData" sender:self];

我正在准备将数据传递到下一个 View Controller :

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if ([[segue identifier] isEqualToString:@"sendUserData"]) {

        UD = (UserDetails *) segue.destinationViewController;

        UD.userFullName.text = self.userFullNameString;

        NSLog(@"FulluserName Segue = %@",UD.userFullName.text);

        NSLog(@"FulluserName Current = %@",self.userFullNameString);

    }
}

Segue ,显示 NextViewController 没有任何问题。问题是 userFullNameString 没有发送到 NextViewController。我正在检查 NSLog ,而 FulluserName Segue 返回 null,FulluserName Current 返回我需要的值。

如何将该数据发送到下一个 View Controller ?

问候..

最佳答案

声明属性

@property (nonatomic, strong)NSString *userFulName;

UserDetails.h 文件中。在你的准备segue方法中

UD.userFulName = self.userFullNameString;

然后在下一个 View Controller (即 UserDetails)的 viewDidLoad

userFullName.text = userFulName;

关于ios - 使用模态 Segue 将数据传递到下一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17327834/

相关文章:

ios - swift - uilalertcontroller 文本字段值返回空

ios - 如何在 Swift 中全局声明数据库连接变量

objective-c - NSBundle pathForResource 不工作

ios - Plist 文件不是通过单击一次按钮从 Web 服务创建的,而是在第二次单击时加载的

iphone - Tableview 自身和 Viewcontroller [多个 Segues]

javascript - 标准化设备方向数据

ios - 如何在初始化后更新自定义类中的 UILabel 文本 (Swift 3)

ios - 突出显示的属性仅用于在 Interface Builder 中显示

ios - UITabBarItem 不更新图像

ios - 添加了导航栏但没有返回按钮?