1

UITableViewCell をカスタマイズしようとしていますが、何らかの理由で空白として表示されます。私が間違っていることは明らかですか?ストーリーボードから menuLabel をアウトレットとして引き出したので、正しく結び付けられ、ストーリーボードのセルはクラス「MenuCell」にリンクされています。

私のテーブルビューコントローラーで

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"MenuCell";
[self.tableView registerClass:[MenuCell class] forCellReuseIdentifier:CellIdentifier];
MenuCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if(cell == nil) {
    NSLog(@"creating a new cell");
    cell = [[MenuCell alloc] initWithStyle:UITableViewCellStyleDefault
                              reuseIdentifier:@"MenuCell"];
}

cell.menuLabel.text = @"Hello";


return cell;
}
4

2 に答える 2

2

これを使用できます

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
        static NSString *CellIdentifier = @"MenuCell";

            MenuCell *cell = (MenuCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            if (cell == nil)
            {
                UINib* customCellNib = [UINib nibWithNibName:@"MenuCell" bundle:nil];

                // Register this nib file with cell identifier.

                [tableView registerNib: customCellNib forCellReuseIdentifier:CellIdentifier];
                cell = (MenuCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            }
    // Whatever you want 
retrun cell;
    }

これが役立つことを願っています。ハッピーコーディング:P

于 2013-09-17T11:08:30.900 に答える