【问题标题】:UITableViewController can not set delegateUITableViewController 不能设置委托
【发布时间】:2019-01-21 14:15:06
【问题描述】:

我只是将 UITableViewController 添加到我的故事板

并将其类设置为名为 CategoriesList 的文件:-

屏幕截图 1:-

屏幕截图 2:-

@interface CategoriesList : UITableViewController {

    NSArray *CategoryArray;


}

@end

但我不断得到

*** 由于未捕获的异常 'NSInvalidArgumentException' 导致应用程序终止,原因:'-[CategoriesList setDelegate:]: unrecognized selector sent to instance 0x7f9bfbd29370'

【问题讨论】:

    标签: objective-c xcode uitableview delegates


    【解决方案1】:

    使用UITableViewController 时,您不需要指定delegatedataSource,因为这已经在内部完成。换句话说,UITableViewController 基本上由一个普通的UIViewController 和一个UITableView 组成,它已经将其delegatedataSource 设置为父控制器。这在 Apple 的文档中有所说明:

    当您的界面由表格视图和很少或没有其他内容组成时,子类 UITableViewController。 表格视图控制器已经采用了您需要的协议来管理表格视图的内容并响应更改

    所以,只需将那些引用到 delegatedataSource 的出口删除就可以了。

    【讨论】:

    • 我做了,但仍然遇到同样的错误,我删除了笔尖并再次添加新的笔尖,没有添加任何内容,只需设置类名,仍然出现相同的错误
    • 我已经创建了新项目并将 UIViewController 添加到 UITableViewController 并且它工作正常,但我在我的项目中执行相同的步骤我不会工作
    【解决方案2】:

    寻找解决方案

    问题是:

    在 UIViewController 上的 prepareForSegue 方法中,该方法具有 UITableViewController 的按钮

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    
        AddMapAddress *MapAddress = [segue destinationViewController];
        MapAddress.delegate = self;
        MapAddress.AnnotationTitle = Name_Txt.text;
    
    }
    

    解决方案:

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    
        if ([[segue identifier] isEqualToString:@"MapSegue"]) {
        AddMapAddress *MapAddress = [segue destinationViewController];
        MapAddress.delegate = self;
        MapAddress.AnnotationTitle = Name_Txt.text;
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-13
      相关资源
      最近更新 更多