gpt4 book ai didi

iphone - iOS:从另一个 View 将新单元格添加到表格 View

转载 作者:行者123 更新时间:2023-11-29 04:55:52 24 4
gpt4 key购买 nike

我想知道在 iOS 中向 tableview 添加新单元格的最佳方法是什么。假设我有一个第一个 View Controller 和一个第二个 View Controller 。在第一个 View Controller 上,我有一个已经填充了一些数据的表格 View ,我还有一个导航栏,顶部有一个添加按钮。点击添加按钮将显示一个新 View ,然后我想将数据从第二个 View Controller 传递到第一个 View Controller 并用它填充我的表格 View 。

谢谢,山姆

最佳答案

您的 SecondViewController 应该创建一个委托(delegate)协议(protocol)。然后你的firstViewController应该被指定为其委托(delegate)。

一旦 SecondViewController 保存数据,它就会调用 FirstViewController 应该实现的方法

这里有一个很好的例子: How do I create delegates in Objective-C?

开始使用:secondViewController.h

@protocol secondViewControllerDelegate;

@interface secondViewController : UIViewController{
id<secondViewControllerDelegate> __unsafe_unretained delegate;
}
@property (nonatomic, unsafe_unretained) id<secondViewControllerDelegate> delegate;
@end

@protocol secondViewControllerDelegate <NSObject>
- (void)dataSaved;
@end

关于iphone - iOS:从另一个 View 将新单元格添加到表格 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7993900/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com