gpt4 book ai didi

ios - 从未调用过 cellForRowAtIndexPath

转载 作者:行者123 更新时间:2023-11-28 21:52:56 32 4
gpt4 key购买 nike

我知道之前有人问过这个问题,但我还没有找到这个特定问题的答案。我已逐步按照苹果教程进行操作,但我无法在表格 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/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com