简体   繁体   中英

cellForRowAtIndexPath for 2 tableview in a storyboard, unrecognized selector sent to instance error

This is my code and my error. I have 2 tableview s in a storyboard with 2 customcell s. But I can't set cellforrowatindexpath method for table2 :

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(tableView.tag==1){
    static NSString *CellIndentifier = @"CustomCell";
    CustomCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIndentifier];
    if (cell==nil) {
        cell=[[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIndentifier];

    }
    cell.text1Label.text=[moviesArray objectAtIndex:indexPath.row];
    cell.text2Label.text=[moviesArraytext2 objectAtIndex:indexPath.row];
        return cell;
    }
    else if (tableView.tag==2){
        static NSString *CellIndentifier2 = @"CategoryCell";
        CategoryCell *cell2=[tableView dequeueReusableCellWithIdentifier:CellIndentifier2];
        if (cell2==nil) {
            cell2=[[CategoryCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIndentifier2];

        }
        cell2.categoryLabel.text=[hotProgramByCatArray objectAtIndex:indexPath.row];
        return cell2;
return nil;

and this is the error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCell categoryLabel]: unrecognized selector sent to instance 0x8e7f560'

Make sure the outlets for the views on the custom cells are wired up to the cell itself and not the "File's Owner".

You can check this by looking at the Connections Inspector in Interface Builder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM