Objective c 自定义UITableviewCell将不会设置标签
我的自定义tableview单元格有问题。当我想在标签上添加文本时,它不会改变。这就是我的代码的样子 我的NieuwsTableViewCell.hObjective c 自定义UITableviewCell将不会设置标签,objective-c,uitableview,Objective C,Uitableview,我的自定义tableview单元格有问题。当我想在标签上添加文本时,它不会改变。这就是我的代码的样子 我的NieuwsTableViewCell.h @interface NieuwsTableViewCell : UITableViewCell{ } @property (nonatomic, retain) IBOutlet UILabel *topic; @property (nonatomic, retain) IBOutlet UILabel *omschrijving; @end
@interface NieuwsTableViewCell : UITableViewCell{
}
@property (nonatomic, retain) IBOutlet UILabel *topic;
@property (nonatomic, retain) IBOutlet UILabel *omschrijving;
@end
我的NieuwsTAbleViewCell.m
@implementation NieuwsTableViewCell
@synthesize topic;
@synthesize omschrijving;
还有我的第一个ViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
NieuwsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray* views = [[NSBundle mainBundle] loadNibNamed:@"NieuwsTableViewCell" owner:nil options:nil];
for (UIView *view in views) {
if([view isKindOfClass:[UITableViewCell class]])
{
NSDictionary *info = [json objectAtIndex:indexPath.row];
cell.topic.text = @"Stef";
cell.omschrijving.text = [info objectForKey:@"Nie_omschrijving"];
NSLog(@"voorlopige test");
cell = (NieuwsTableViewCell*)view;
}
}
}
return cell;
}
这是因为您正在if(!cell)块内设置text属性。该块只会被调用几次以创建可重用对象。简单地说,将单元格移动到if(!cell)块外。*.text=部分。这是一个完整的JIC代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
NieuwsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray* views = [[NSBundle mainBundle] loadNibNamed:@"NieuwsTableViewCell" owner:nil options:nil];
for (UIView *view in views) {
if([view isKindOfClass:[UITableViewCell class]])
{
cell = (NieuwsTableViewCell*)view;
}
}
}
NSDictionary *info = [json objectAtIndex:indexPath.row];
cell.topic.text = @"Stef";
cell.omschrijving.text = [info objectForKey:@"Nie_omschrijving"];
NSLog(@"voorlopige test");
return cell;
}