Ios 加载带表的UIView时,无法从其数据源获取单元格 我有一个VIEW控制器,我把另一个小的UIVIEW放在中间,我放了一个TabLVIEW,但是不知道如何在这个表中显示数组中的数据,任何帮助都将非常感谢。我正在尝试使用以下代码加载表: -(void) animateResults { _resultsLabel.text = [NSString stringWithFormat:@"You Scored %d", runningScore ]; resultsTable.delegate = self; resultsTable.dataSource = self; [self.resultsTable registerClass:[UITableViewCell self] forCellReuseIdentifier:@"resultsListCell"]; [self.resultsTable reloadData]; [self.view layoutIfNeeded]; [UIView animateWithDuration:0.3 animations:^{ _resultsView.frame = self.view.frame; } completion:^(BOOL finished){ NSLog(@"%@", questionsArray); }]; }

Ios 加载带表的UIView时,无法从其数据源获取单元格 我有一个VIEW控制器,我把另一个小的UIVIEW放在中间,我放了一个TabLVIEW,但是不知道如何在这个表中显示数组中的数据,任何帮助都将非常感谢。我正在尝试使用以下代码加载表: -(void) animateResults { _resultsLabel.text = [NSString stringWithFormat:@"You Scored %d", runningScore ]; resultsTable.delegate = self; resultsTable.dataSource = self; [self.resultsTable registerClass:[UITableViewCell self] forCellReuseIdentifier:@"resultsListCell"]; [self.resultsTable reloadData]; [self.view layoutIfNeeded]; [UIView animateWithDuration:0.3 animations:^{ _resultsView.frame = self.view.frame; } completion:^(BOOL finished){ NSLog(@"%@", questionsArray); }]; },ios,objective-c,uitableview,Ios,Objective C,Uitableview,但是现在我收到了一个从数据源获取单元格失败的消息。这是表格的代码 -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { //Return number of sections return 1; } //get number of rows by counting number of challenges -(NSInteger)tableView:(UITableView *)tableView numberO

但是现在我收到了一个从数据源获取单元格失败的消息。这是表格的代码

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//Return number of sections
return 1;

}

//get number of rows by counting number of challenges
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section {
return questionsArray.count;
}


//setup cells in tableView
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath{
//setup cell
static NSString *CellIdentifier = @"resultsListCell";
resultsViewCell *cell = [tableView  dequeueReusableCellWithIdentifier:CellIdentifier];

NSDictionary *results = [questionsArray objectAtIndex:indexPath.row];

NSString *resultsName = [results objectForKey:@"answers"];

BOOL correct = [[results objectForKey:@"correct"] boolValue];

if (!correct) {
    cell.resultsIcon.image = [UIImage imageNamed:@"BlackIconLock.png"];
}

else{
    cell.resultsIcon.image = nil;
}

cell.resultsName.text = resultsName;

return cell;
}
这是这个视图控制器的.h

#import <UIKit/UIKit.h>
#import "Store.h"
#import "flags.h"
#import "Tribes.h"
#import "resultsViewCell.h"

@interface GamePlayViewController : UIViewController <UITableViewDataSource,UITableViewDelegate>{

NSMutableArray *questionsArray;
NSMutableArray *answersArray;
NSInteger gameSelected;
NSMutableArray *revealArray;
NSTimer *questionTimer;
BOOL GameInProgress;

int random;
int questionTimerCounter;
int loopCounter;
int runningScore;

}

@property (weak, nonatomic) IBOutlet UIImageView *questionImage;
@property (weak, nonatomic) IBOutlet UILabel *answerLabel1;
@property (weak, nonatomic) IBOutlet UILabel *answerLabel2;
@property (weak, nonatomic) IBOutlet UILabel *answerLabel3;

- (IBAction)answer1:(id)sender;
- (IBAction)answer2:(id)sender;
- (IBAction)answer3:(id)sender;

@property (weak, nonatomic) IBOutlet UIImageView *cover1;
@property (weak, nonatomic) IBOutlet UIImageView *cover2;
@property (weak, nonatomic) IBOutlet UIImageView *cover3;
@property (weak, nonatomic) IBOutlet UIImageView *cover4;
@property (weak, nonatomic) IBOutlet UIImageView *cover5;
@property (weak, nonatomic) IBOutlet UIImageView *cover6;
@property (weak, nonatomic) IBOutlet UIImageView *cover7;
@property (weak, nonatomic) IBOutlet UIImageView *cover8;
@property (weak, nonatomic) IBOutlet UIView *coreView;

@property (weak, nonatomic) IBOutlet UILabel *resultsLabel;
@property (strong, nonatomic) IBOutlet UITableView *resultsTable;
@property (weak, nonatomic) IBOutlet UIView *resultsView;

@end

根据上面提供的代码,我假设您使用的是自定义单元格。您应该注册该resultsViewCell

viewDidLoad中注册该自定义单元格

[self.resultsTable registerNib:[UINib nibWithNibName:@"NAME_OF_YOUR_CELL_NIB" bundle:nil] forCellReuseIdentifier:@"resultsListCell"];

我注意到,在您的animateResults方法中,您正在将self分配给resultsTable的代理和数据源,它不应该是self.resultsTable\u resultsTable

首先检查您的
问题数组
。它不能有任何空对象


第二,如果您使用的是“故事板中的单元格”意思是“直接从
表视图”
,那么为什么要注册它?

我认为这些
结果表.delegate=self
resultsTable.dataSource=self应位于
viewDidLoad
中。另外,如果你的单元格有自定义类和自定义.xib,那么你必须注册它。如果两者都不是真的,请尝试将数据记录下来,看看它是否包含任何内容。当我加载委托和数据源时,我正在加载带有表的UIView。至于阵列中的数据,我已经记录下来,它显示数据实际上已经准备好加载,但我假设在单元加载期间我遗漏了一些东西。你有自定义单元类和自定义xib吗?如果不是,请确保您的tableView不是nil,请在设置数据源和委派之前记录它。是的,我只是更新了帖子以反映结果视图单元格。h文件。尝试删除代码中的
cell.resultsIcon.image…
行,看看它是否有效?否则,请尝试查看您是否连接了错误的IBOutlet或其他内容。我已经用您提出的建议更新了帖子,但仍然收到未识别的NSInvalidArgumentException',原因:'-[UITableViewCell resultsIcon]:未识别的选择器发送到实例。哦,是的,我也会改变自己。要删除self.resultsTable.delegate并删除=self?请确保您的自定义单元格(xib)在其.h文件中声明了其resultsIcon。您需要注册Nib,我不确定您注册自定义单元格的方式是否有效。您能像上面提供的示例那样将它更改为registerNib吗?那么我在回答中问的resultsTable问题呢?我不使用nib文件,只使用情节提要在这种情况下,您可以将情节提要中的自定义单元格拖动到情节提要中的UITableView。这样做不需要您注册自定义单元格。欢迎Joe。你可能想接受你这个问题的答案。
[self.resultsTable registerNib:[UINib nibWithNibName:@"NAME_OF_YOUR_CELL_NIB" bundle:nil] forCellReuseIdentifier:@"resultsListCell"];