1

ストーリーボードのuitableviewで、プロトタイプセルを定義しました。そのセル(カスタムクラスkzTexturedCellv2)には、テキストビューと画像ビューがあります。また、セルに識別子( "kzTexturedCellv2")を付けて、

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

kzTexturedCellv2 *cell = [[kzTexturedCellv2 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"kzTexturedCellv2"];

...

セルを作成します。問題は、セルが空白で表示されることです(storyboadで追加したサブビューはありません)。セル内にuitextviewのテキストを設定しようとすると、常にnullが返されます。ここで何が起こっているのですか?

4

2 に答える 2

6

ストーリーボードを使用する場合、セルを初期化する必要はありません。

プロトタイプセルのdequeueReusableCellWithIdentifierの動作が変更されましたか?を参照してください。

使用のみ:

kzTexturedCellv2 *cell = [tableView dequeueReusableCellWithIdentifier:@"kzTexturedCellv2"];

Allocinitはフレームワークによって処理されます

于 2012-05-28T04:43:55.617 に答える
0

plzは次のコードを見ることができますか。お役に立てば幸いです

- (void)viewDidLoad{
[super viewDidLoad];

// Create your image
UIImage *image = [UIImage imageNamed: @"person_menu.png"];
UIBarButtonItem *barButton = [[UIBarButtonItem alloc]
                              initWithImage:image
                              style:UIBarButtonItemStylePlain
                              target:nil
                              action:nil];
// set the text view to the image view
self.navigationItem.leftBarButtonItem = barButton;

menuItems = @[@"title", @"Payment", @"History",@"BookNow",@"Help", @"Promotions",@"Notifications", @"Settings", @"logOut"];
}
#pragma mark
#pragma mark - UITableViewDelegate Methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
// Return the number of sections.
return 1;
}

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
// Return the number of rows in the section.
return [menuItems count];
}
 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row == 0) {
    return 140;
}else{
     return  75;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *CellIdentifier = [menuItems objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.highlighted = YES;
return cell;
}

UITableviewCellにある識別子が何であれ、それらを収集して1つのNSArrayに追加できます。

あなたの場合は、次のように使用できます::

kzTexturedCellv2 *cell = [tableView dequeueReusableCellWithIdentifier:@"kzTexturedCellv2"];
于 2016-01-06T06:26:08.190 に答える