gpt4 book ai didi

ios - TableView 不会加载任何数据

转载 作者:行者123 更新时间:2023-11-28 22:13:14 30 4
gpt4 key购买 nike

在这个上扯掉了我的头发。我已经制作了很多带有表格 View 的应用程序,并且一直在查看我过去的应用程序,但是由于某种原因,这个表格 View 太顽固了,无法显示任何东西......

- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.delegate = self;
self.tableView.datasource = self;

[_myArray addObject:@"Hi"];
[_myArray addObject:@"Hello"];
[_myArray addObject:@"Bye"];

// 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
{
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section
{
return [_myArray count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
NSString *currentItem = [_myArray objectAtIndex:indexPath.row];

cell.textLabel.text = @"Hi";

// Configure the cell...

return cell;
}

所以基本上什么都没有显示给我。即使我设置了委托(delegate),并在 .h 文件中获取了 TableView 委托(delegate)和数据源, TableView 仍然一如既往地空白。

最佳答案

初始化你的数组。 _myArray = [[NSMutableArray 分配] 初始化];

关于ios - TableView 不会加载任何数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22367044/

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