【问题标题】:how to pass data from tableview to another tableview cell?如何将数据从 tableview 传递到另一个 tableview 单元格?
【发布时间】:2013-04-10 09:42:30
【问题描述】:

我正在使用静态UITableView 来显示客户的个人资料。

它具有 SelectCountryCell 来选择国家/地区,单击该国家/地区会打开带有国家/地区列表的新 UITableView

当我从 Country TableView 中选择国家时,它应该显示在前一个 TableView 的 SelectCountryCell 中。

我该怎么做?

【问题讨论】:

    标签: ios uitableview


    【解决方案1】:

    您应该将静态单元绑定到您的UITableViewController 中的插座,并将配置文件同步方法放入- viewWillAppear 方法。

    当用户更改国家/地区列表中的国家/地区时,配置文件会更新。之后,当用户移回具有静态内容的UITableViewController 实例时,配置文件数据将自动更新。

    【讨论】:

      【解决方案2】:

      您可以在 CityTableView 中定义一个委托,然后在此委托中定义一个方法。

      你应该在你的 CountryTableView 中实现这个方法。

      那么你可能会得到你想要的。

      我只给你一个想法。你应该自己找到细节。

      【讨论】:

        【解决方案3】:

        MasterViewController.h

        #import "DetailViewController.h"
        
        @interface MasterViewController : UITableViewController <DetailProtocol> // Note this.
        
        @property (strong, nonatomic) DetailViewController *detailViewController;
        @property (strong, nonatomic, readwrite) NSString *selectedCountry;
        
        @end
        

        MasterViewController.m

        - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
        {
            if (!self.detailViewController) {
                self.detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
            }
            self.detailViewController.delegate = self; // THIS IS IMPORTANT...
            [self.navigationController pushViewController:self.detailViewController animated:YES];
        }
        
        // Note this -- It's a delegate method implementation
        - (void)setCountry:(NSString *)country
        {
            self.selectedCountry = country;
        }
        

        DetailViewController.h

        @protocol DetailProtocol <NSObject>
        -(void)setCountry:(NSString *)country;
        @end
        
        @interface DetailViewController : UIViewController
        
        @property (strong, nonatomic) IBOutlet UITableView *tableView;
        @property (unsafe_unretained) id <DetailProtocol> delegate; // Note this
        
        @end
        

        DetailViewController.m

        - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
        {
            [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
            [self.delegate setCountry:[countries objectAtIndex:indexPath.row]]; // Note this
            [self.navigationController popViewControllerAnimated:YES];
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-03-14
          • 2021-08-30
          • 1970-01-01
          • 2017-04-16
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多