如何从视图中获取数据到UitabbarController

问题描述 投票:0回答:1
我有一个,有一个。每个控制器都有几个。在

UITabBarController

中是一个按钮“保存”。拜托,如何从
3 UIViewControllers
中获取数据?我需要来自所有
UITextFields
的数据,以及所有
UItabBarController
(在保存按钮的ibaction中)。我该怎么做?谢谢
在故事板上我的tabbarcontroller的图片。
第一个ViewController具有class studentvc。该类有一个文本字段。在
studentvc.m
中是此代码:
UITextFields
StudentNameTextfield与情节板中的字段相连。然后,我有一个塔巴尔的课程,班级名称为StudentTBC。在文件

studenttbc.m

i有此代码:

UIViewControlloresenter image description here

,当我上塔巴尔时,我会在StudentNametextfield中看到文本“ ASAD”,但字段很明确...所以我在iBaction中也添加了:保存此代码:

UITextFields

但是,当我插入字段并按“ ulozit”(其保存在捷克)时,我会得到一个“字符串:null”,而不是“字符串:textwhichiwriteteTofield”。我尝试了索引0,1,2,但无效。 :/

已编辑了3.4 15:20

我对我的申请做了一步。第一部分是我的故事板-UitabbarController和3UiviewControllers。我删除了导航控制器。在第二部分中,我再次做一个媒体。第三部分是保存函数的代码(代码可以编写TextField的内容)和TabBarController的ViewDidload代码(可以将代码设置为TextField的字符串)。最后一部分是运行应用程序(结果是在控制台-NULL字符串和清除文本字段中)。
我还尝试打印以下内容:

UIViewControllers

它必须是三个?或者?因为我的结果是0 ..为什么? :/
我的电影:

https://www.youtube.com/watch?v = j6p__e48lli&feature =youtu.be

已编号2.4 20:58 -------------------------------------------------------------------------------------------------------------------------

Hello。我尝试了所有选项,但是什么也没有用。因此,我做了一个新的简单应用程序,其中只有一个带有两个UiviewControllers和一名UitaiteViewController(由于导航栏)的UitabbarController。请下载该项目并自己尝试。仅运行,然后单击“ tabar”按钮,然后在uitabbarcontroller上。按下保存按钮时,它应显示uiviewscontrollers的数量和文本场的值。您能尝试告诉我怎么了吗?谢谢。这是项目:

https://www.dropbox.com/s/r4jlzadr2us00ad/tbc.zip

    

要访问文本字段之一,您可以在下面使用代码:

UITabBarController

您有我的控制器如何连接,现在我意识到您在

#import <UIKit/UIKit.h> #import "CoreDataHelper.h" @interface StudentVC : UIViewController <UITextFieldDelegate> @property (strong, nonatomic) NSManagedObjectID *selectedStudentID; @property (strong, nonatomic) IBOutlet UIScrollView *scrollView; @property (strong, nonatomic) IBOutlet UITextField *studentNameTextField; @end 之后得到了- (void)viewDidLoad { if (debug == 1) { NSLog(@"Running %@ '%@'", self.class, NSStringFromSelector(_cmd)); } [super viewDidLoad]; StudentVC *studentVC = [self.tabBarController.viewControllers objectAtIndex:0]; studentVC.studentNameTextField.text = @"asad"; }

。修改的代码应该看起来像:

- (IBAction)save:(id)sender { if (debug == 1) { NSLog(@"Running %@ '%@'", self.class, NSStringFromSelector(_cmd)); } StudentVC *studentVC = [self.tabBarController.viewControllers objectAtIndex:0]; NSString *string = studentVC.studentNameTextField.text; NSLog(@"string:%@", string);

任期

ios objective-c uitabbarcontroller getter
1个回答
2
投票
i最终解决了问题... TABBARCONTROLLER的正确代码

NSInteger countOfViews = [self.tabBarController.viewControllers count]; NSLog(@"count:%ld", (long)countOfViews);


请检查

UTLETS
uitextfields

也检查输出

NSLOG(@“ StudentVC Textfield -%@”,StudentVC.StudentNametextfield); save()

如果也是无效的,那么您的插座肯定存在问题。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.