我想知道在 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/