0

アプリで SplitViewController を使用しています。ここのマスター ViewController では、 Custom table を使用しています。 これがMaster View Controllerのイメージです

コードは次のとおりです。

self.items = [NSMutableArray arrayWithObjects:@"About Company", @"Contact Us", @"Nearest Center",  nil];

[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionMiddle];

self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.rowHeight = 100;
    self.tableView.backgroundColor = [UIColor purpleColor];




#pragma mark - UITableViewDataSource

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

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

}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return @" " ;
}

- (UITableViewCell *)tableView:(UITableView *)atableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
#if USE_CUSTOM_DRAWING
    const NSInteger TOP_LABEL_TAG = 1001;
    const NSInteger BOTTOM_LABEL_TAG = 1002;
    UILabel *topLabel;
    UILabel *bottomLabel;
#endif
    static NSString *CellIdentifier = @"Cell"; // <-- Make sure this matches what you have in the storyboard

    UITableViewCell *cell = [atableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
#if USE_CUSTOM_DRAWING
        UIImage *indicatorImage = [UIImage imageNamed:@"indicator.png"];
        cell.accessoryView =  [[UIImageView alloc]initWithImage:indicatorImage];

        const CGFloat LABEL_HEIGHT = 20;
        UIImage *image = [UIImage imageNamed:@"imageA.png"];

        //
        // Create the label for the top row of text
        //
        topLabel =[[UILabel alloc]initWithFrame:CGRectMake(image.size.width + 2.0 * cell.indentationWidth,
                       0.5 * (atableView.rowHeight - 2 * LABEL_HEIGHT),
                     atableView.bounds.size.width -
                     image.size.width - 4.0 * cell.indentationWidth
                     - indicatorImage.size.width,
                     LABEL_HEIGHT)] ;
        [cell.contentView addSubview:topLabel];

        //
        // Configure the properties for the text that are the same on every row
        //
        topLabel.tag = TOP_LABEL_TAG;
        topLabel.backgroundColor = [UIColor clearColor];
        topLabel.textColor = [UIColor colorWithRed:0.25 green:0.0 blue:0.0 alpha:1.0];
        topLabel.highlightedTextColor = [UIColor colorWithRed:1.0 green:1.0 blue:0.9 alpha:1.0];
        topLabel.font = [UIFont systemFontOfSize:[UIFont labelFontSize]];

        //
        // Create the label for the top row of text
        //
        bottomLabel =[[UILabel alloc]initWithFrame:CGRectMake(image.size.width + 2.0 * cell.indentationWidth,
                     0.5 * (atableView.rowHeight - 2 * LABEL_HEIGHT) + LABEL_HEIGHT,
                     atableView.bounds.size.width -
                     image.size.width - 4.0 * cell.indentationWidth
                     - indicatorImage.size.width, LABEL_HEIGHT)];
                [cell.contentView addSubview:bottomLabel];

        //
        // Configure the properties for the text that are the same on every row
        //
        bottomLabel.tag = BOTTOM_LABEL_TAG;
        bottomLabel.backgroundColor = [UIColor clearColor];
        bottomLabel.textColor = [UIColor colorWithRed:0.25 green:0.0 blue:0.0 alpha:1.0];
        bottomLabel.highlightedTextColor = [UIColor colorWithRed:1.0 green:1.0 blue:0.9 alpha:1.0];
        bottomLabel.font = [UIFont systemFontOfSize:[UIFont labelFontSize] - 2];

        //
        // Create a background image view.
        // 
        cell.backgroundView = [[UIImageView alloc] init];

        cell.selectedBackgroundView =[[UIImageView alloc] init];
      //  cell.selectionStyle = UITableViewCellSelectionStyleNone;
#endif
    }

#if USE_CUSTOM_DRAWING
    else
    {
        topLabel = (UILabel *)[cell viewWithTag:TOP_LABEL_TAG];
        bottomLabel = (UILabel *)[cell viewWithTag:BOTTOM_LABEL_TAG];
    }

    topLabel.text = [self.items objectAtIndex:indexPath.row];
    bottomLabel.text = [self.items objectAtIndex:indexPath.row];

    //
    // Set the background and selected background images for the text.
    // Since we will round the corners at the top and bottom of sections, we
    // need to conditionally choose the images based on the row index and the
    // number of rows in the section.
    //
    UIImage *rowBackground;
    UIImage *selectionBackground;
    NSInteger sectionRows = [atableView numberOfRowsInSection:[indexPath section]];
    NSInteger row = [indexPath row];
    if (row == 0 && row == sectionRows - 1)
    {
        rowBackground = [UIImage imageNamed:@"topAndBottomRow.png"];
        selectionBackground = [UIImage imageNamed:@"topAndBottomRowSelected.png"];
    }
    else if (row == 0)
    {
        rowBackground = [UIImage imageNamed:@"topRow.png"];
        selectionBackground = [UIImage imageNamed:@"topRowSelected.png"];
    }
    else if (row == sectionRows - 1)
    {
        rowBackground = [UIImage imageNamed:@"bottomRow.png"];
        selectionBackground = [UIImage imageNamed:@"bottomRowSelected.png"];
    }
    else
    {
        rowBackground = [UIImage imageNamed:@"middleRow.png"];
        selectionBackground = [UIImage imageNamed:@"middleRowSelected.png"];
    }
    ((UIImageView *)cell.backgroundView).image = rowBackground;
    ((UIImageView *)cell.selectedBackgroundView).image = selectionBackground;

    //
    // Here I set an image based on the row. This is just to have something
    // colorful to show on each row.
    //


    switch ([indexPath row]) {
        case 0:
            cell.imageView.image = [UIImage imageNamed:@"imageA.png"];
            break;
        case 1 :
            cell.imageView.image = [UIImage imageNamed:@"imageB.png"];
            break;
        default:
            break;
    }


#else
    //cell.text = [NSString stringWithFormat:@"Cell at row %ld.", [indexPath row]];



    // Configure the cell.
    cell.textLabel.text = [self.items objectAtIndex:indexPath.row]; // Set the MasterViewController's tableView row "Cell" to display selected  array element
   #endif

    return cell;
}

これが私が得ているエラーです:

-[UITableViewCellSelectedBackground setImage:]: 認識されないセレクターがインスタンス 0x7616300 2013-04-16 11:41:40.841 ICare[1144:c07] に送信されましたインスタンス 0x7616300 に送信された認識されないセレクター' *First throw call stack: (0x1532012 0x1357e7e 0x15bd4bd 0x1521bbc 0x152194e 0xa3da 0x7358fb 0x7359cf 0x71e1bb 0x71c872 0x7275d4 0x72a1c4 0x72a546 0x85ab 0x75c1c7 0x75c232 0x75c4da 0x7738e5 0x7739cb 0x773c76 0x773d71 0x77489b 0x7749b9 0x774a45 0x87a20b 0x6cb2dd 0x136b6b0 0x19ffc0 0x19433c 0x19feaf 0x76a2bd 0x6b2b56 0x6b166f 0x6b1589 0x6b07e4 0x6b061e 0x6b13d9 0x6b42d2 0x75e99c 0x6ab574 0x6ab76f 0x6ab905 0x6b4917 0x67896c 0x67994b 0x68acb5 0x68bbeb 0x67d698 0x2629df9 0x2629ad0 0x14a7bf5 0x14a7962 0x14d8bb6 0x14d7f44 0x14d7e1b 0x67917a ablced ablceed

私は何かを逃した。しかし、私はそれを解決できません.IOS開発は初めてです。

ヘルプや提案をいただければ幸いです。ありがとうございました。

4

1 に答える 1