【发布时间】:2016-04-16 04:23:46
【问题描述】:
我有一个 ViewController,我在其中放置了另一个小的 UIView,其中我放置了一个 TableView,但不确定如何在此表中显示数组中的数据,任何帮助将不胜感激。我正在尝试使用以下代码加载表格:
-(void) animateResults {
_resultsLabel.text = [NSString stringWithFormat:@"You Scored %d", runningScore ];
resultsTable.delegate = self;
resultsTable.dataSource = self;
[self.resultsTable registerClass:[resultsViewCell self] forCellReuseIdentifier:@"resultsListCell"];
[self.resultsTable reloadData];
[self.view layoutIfNeeded];
[UIView animateWithDuration:0.3 animations:^{
_resultsView.frame = self.view.frame;
} completion:^(BOOL finished){
NSLog(@"%@", questionsArray);
}];
}
我在 TableView 中使用自定义单元来加载 NSMutableArray。我已经尝试将此代码用于表格视图:
-(NSInteger)numberOfSectionsInTableView:(resultsViewCell *)tableView {
//Return number of sections
return 1;
}
//get number of rows by counting number of challenges
-(NSInteger)tableView:(resultsViewCell *)tableView numberOfRowsInSection:(NSInteger)section {
return questionsArray.count;
}
//setup cells in tableView
-(resultsViewCell *)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;
}
但 _resultsView 不加载不知道为什么。到目前为止,我得到了很多很大的帮助,我真的很感激。我已经在这一点上停留了大约 2 周。请帮忙!
【问题讨论】:
-
检查
_resultView是否为nil。 -
抱歉,我刚开始学习这项学习,我该如何检查?再次为noobness道歉
-
在
animateResults的开头添加NSLog(@"resultsView: %@", _resultsView)行,运行应用程序并查看控制台输出。如果它打印resultsView: (null),则视图为零。 -
您必须先初始化视图才能使用它。
标签: ios objective-c uitableview uiview