作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我知道之前有人问过这个问题,但我还没有找到这个特定问题的答案。我已逐步按照苹果教程进行操作,但我无法在表格 View 中看到我的数据。
问题是函数“cellForRowAtIndexPath”从未被调用,尽管 numberOfSectionsInTableView 返回 1 并且 numberOfRowsInSection 也返回。
这是我的代码:
#import "StudentListTableViewController.h"
#import "Student.h"
@interface StudentListTableViewController ()
@end
@implementation StudentListTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self loadInitialData];
NSLog(@"yes");
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
NSLog(@"NUMBERS OF SECTION IN TABLE");
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
NSLog(@"NUMBER OF ROWS");
return self.studentList.count;
}
-(void) loadInitialData
{
NSLog(@"LOAD INITIAL DATA");
self.studentList = [[NSMutableArray alloc] init];
Student* s1 = [[Student alloc] init];
s1.firstName = @"moses";
s1.lastName = @"gonzales";
s1.phoneNumber = @"050-20202020";
s1.studentID = @"90123456";
/* Student* s2 = [[Student alloc] init];
s2.firstName = @"roman";
s2.lastName= @"wolf";
s2.phoneNumber = @"050123456789";
s2.studentID = @"39393939";
*/
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"prototypeCell" forIndexPath:indexPath];
NSLog(@"fcell");
// Configure the cell...
Student* s = [self.studentList objectAtIndex:indexPath.row];
cell.textLabel.text = s.firstName;
return cell;
}
和平:)
最佳答案
您的 self.studentList
是空数组,因此它返回 0 作为计数。如果 UITableView
有 0 个部分,则它不会调用其 cellForRowAtIndexPath:
。尝试更改您的 loadInitialData
方法。(将 s1
添加到 self.studentList)。
关于ios - 从未调用过 cellForRowAtIndexPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27639404/
背景 我最近在 merge 期间遇到了一个意外未 merge 的文档文件的问题。 无论出于何种原因,我搞砸了 merge 并有效地删除了文件(和其他几个文件),因为我忘记了它们的存在。 现在我想查看我
我在我的网站上使用旧的 mysql 版本和 php 版本 4。 我的表结构: | orders_status_history_id | orders_id | orders_status_id |
我是一名优秀的程序员,十分优秀!