Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在自定义UIview中设置UItableview的委托和数据源_Ios_Objective C_Uitableview_Uiview - Fatal编程技术网

Ios 在自定义UIview中设置UItableview的委托和数据源

Ios 在自定义UIview中设置UItableview的委托和数据源,ios,objective-c,uitableview,uiview,Ios,Objective C,Uitableview,Uiview,我有一个自定义的UIView,它有几个不同的视图,还有一个UITableview 我创建了一个自定义类,它是UITableViewController的子类。这将控制UITableview和UITableview的原型单元格 如果将委托和数据源设置为父视图,则会出现以下错误: -[RoadSafetyAppViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x10c92

我有一个自定义的
UIView
,它有几个不同的视图,还有一个
UITableview

我创建了一个自定义类,它是
UITableViewController
的子类。这将控制
UITableview
UITableview
的原型单元格

如果将委托和数据源设置为父视图,则会出现以下错误:

-[RoadSafetyAppViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x10c92f190
其中RoadSafetyAppView控制器是父视图。但是,如果我根本没有设置委托和数据源,我的表就不会加载我在自定义类中声明的映像,如下所示:

@implementation MenuController
@synthesize menuArray;

-(void) viewDidLoad
{
    [super viewDidLoad];


    self.menuArray = [NSMutableArray arrayWithCapacity:4];
    [menuArray addObject:[UIImage imageNamed:@"Dob in a Hoon menu.png"]];
    [menuArray addObject:[UIImage imageNamed:@"Report a Hazard menu.png"]];
    [menuArray addObject:[UIImage imageNamed:@"Old Logo menu.png"]];
    [menuArray addObject:[UIImage imageNamed:@"Council Website menu.png"]];
}


-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.menuArray count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"CellIdentifier";
    MenuCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];


    cell.menuImage.image =[UIImage imageNamed:@"Dob in a Hoon menu.png"];

    switch (indexPath.row) {
        case 0:
            cell.menuImage.image =[UIImage imageNamed:@"Dob in a Hoon menu.png"];
            break;
        case 1:
            cell.menuImage.image =[UIImage imageNamed:@"Report a Hazard menu.png"];
            break;
        case 2:
            cell.menuImage.image =[UIImage imageNamed:@"Old Logo menu.png"];
            break;
        case 3:
            cell.menuImage.image =[UIImage imageNamed:@"Council Website menu.png"];
            break;
        default:
            break;
    }


    return cell;
}
有人能指出我的图像哪里出了问题,或者我需要将委托/数据源设置为什么


谢谢。

在您的菜单控制器上。h

MenuController : UIViewController<UITableViewDelegate,UITableViewDataSource>
MenuController:UIViewController
并将UITableView与Interface Builder中的委托和数据源连接


希望它能解决你的问题

通过在菜单控制器的viewDidLoad方法中编码来设置委托和数据源

_tblView.delegate = self;
_tblView.dataSource = self;

看起来您应该将
委托
数据源
设置为
MenuController
实例,而不是
RoadSafetyAppViewController
。是否
RoadSafetyAppViewController
MenuController
的父级?将
delegate
datasource
设置为
MenuController
并检查。menuArray是否已初始化?我无法控制并从tableview拖动到delegate或datasource。您需要如上所述声明委托以使其控制并从tableview拖动到delegate和datasource。。。!我已经按照您的建议修改了我的.h文件,但仍然无法从我的表视图数据源拖动到表视图。您是否已在Interface Builder中将文件所有者设置为MenuViewController..请检查..这可能是问题。。!是的,但当我离开identity inspector时,自定义类将更改回UITableview。我无法执行此操作,因为某些原因,我无法将我的IBoutlet链接到tableview。控件+拖动不允许我在.hfile中选择IBOutlet