且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过点击按钮将tableViewCell添加到新的TableView中

更新时间:2023-12-02 22:13:58

执行此操作的方法有很多,并且由于您尚未指定何时何地使用收藏夹表视图,因此一种解决方案可能对您有用的是使用NSUserDefaults.

There are many ways to do this, and since you haven't specified when or where you're going to be using your Favorites Table View, one solution that might work for you is to use NSUserDefaults.

当用户点击收藏夹"按钮时(假设您已经创建并初始化了一个数组)

When the user hits the favorite button (Assuming you've already created and initialized an array)

[favoritesArray addObject:Car1];

[[NSUserDefaults standardUserDefaults] setObject:favoritesArray forKey:@"favoriteCars"];

然后当您需要访问此数组以用作另一个视图控制器中的收藏夹" TableView的数据源时:

And then when you need to access this array to use as the data source for your Favorites TableView in another view controller:

NSMutableArray *array = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:@"favoriteCars"]];