Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 自定义UITableviewCell将不会设置标签_Objective C_Uitableview - Fatal编程技术网

Objective c 自定义UITableviewCell将不会设置标签

Objective 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

我的自定义tableview单元格有问题。当我想在标签上添加文本时,它不会改变。这就是我的代码的样子

我的NieuwsTableViewCell.h

@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;
}