如何将视图 B 中的文本字段内容发送到视图 A?

发布于 2024-12-27 03:20:17 字数 538 浏览 2 评论 0原文

我在 UIView A 中创建了一个 tableview A,其中包含来自 Am 文件中定义的 plist 文件的 tabledatasourcetableview 中的条目是带有 keyAkeyBkeyC 等的字典。

现在我要走了在UIView A中创建一个UIButton,并创建一个新的modalview B。按下按钮时,会弹出modalview B。在模态视图 B 中,会有一些 UITextfields 供用户填写。用户在文本字段中填写的信息将写入plist文件(如上所述),然后重新加载表格视图A的内容。

我的问题是,用户在模态视图B中填写信息。但是表格视图A位于< code>UIView A. 好像我当前在modalview B上使用App时无法更改tableview A的内容?

是否有办法可以将视图 B 中输入的信息传递到视图 A? 多谢。

I created a tableview A in UIView A, with a tabledatasource from a plist file defined in the A.m file. The entries in the tableview are dictionaries with keyA, keyB, keyC, and etc.

Now I'm going to create a UIButton in UIView A and a new modalview B. When the button is pressed , modalview B will pop up. In modalview B, there will be a few UITextfields to be filled in by the users. The information that user fill in the textfields will write to the plist file(as mentioned above), and then reload the content of the tableview A.

My question is, users fill in informations in modalview B. But the tableview A is in the UIView A. It seems that I can not change the content of tableview A when I am currently using the App on the modalview B?

If there's a way that I can pass the informations entered in view B to view A?
Thanks a lot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不美如何 2025-01-03 03:20:17

使用自定义协议 - 这称为委托模式

//ClassA.h

@interface : ClassA{
}
@end

ClassB.h

@protocol ClassBDelegate;

@interface :  ClassB{

    id <ClassBDelegate> delegate
}

@property(nonatomic,assign)   id <ClassBDelegate> delegate;
@end
@protocol ClassBDelegate <NSObject>

-(void)classB:(ClassB*)bclass param1:(NSString*)p1 param2:(NSString*)p2 param3:(NSString*)p3;

@end

将委托设置为 ClassA -

按钮操作中的接收器(在 b 类中)
只是说

[self.delegate classB:self param1:@"Param1" param2:@"P2" param3:@"p3"];

Use custom Protocals - This is called delegate pattern

//ClassA.h

@interface : ClassA{
}
@end

ClassB.h

@protocol ClassBDelegate;

@interface :  ClassB{

    id <ClassBDelegate> delegate
}

@property(nonatomic,assign)   id <ClassBDelegate> delegate;
@end
@protocol ClassBDelegate <NSObject>

-(void)classB:(ClassB*)bclass param1:(NSString*)p1 param2:(NSString*)p2 param3:(NSString*)p3;

@end

Set delegate to ClassA - receiver

In button action (in Class b)
just say

[self.delegate classB:self param1:@"Param1" param2:@"P2" param3:@"p3"];
岁月打碎记忆 2025-01-03 03:20:17

您通常使用委托模式来实现此行为。查看 Apple 文档中的 iPhoneCoreDataRecipes 示例。特别是查看类

  • RecipeListTableViewController,其中表视图 A 将是
  • RecipeAddViewController,模态视图 B 将在其中获取信息

You typically achieve this behavior using the delegate pattern. Check out the example iPhoneCoreDataRecipes in the Apple documentation. In particular look at the classes

  • RecipeListTableViewController, where your table view A is going to be
  • RecipeAddViewController, the modal view B where you get the information
烟燃烟灭 2025-01-03 03:20:17

我想我误解了你的问题。好的,就像 sanjeev 说的那样,你可以使用代表。或者你可以使用 NSNotification。在视图 A 和要修改 plist 的视图 B 中添加通知观察者发布通知。
查看此示例

I think i misunderstood your question. ok so like sanjeev said you can use delegates. Or you can use NSNotification. Add a notification Observer in View A and in view B where you are modifying plist Post a notification.
See This Example

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文