gpt4 book ai didi

iOS : reloadData not working

转载 作者:行者123 更新时间:2023-11-29 03:09:04 26 4
gpt4 key购买 nike

我是整个 iOS 开发的新手,所以不是很擅长。我目前有一个带有两个 TableView 的 viewController。第一个表始终可见并包含类别。只有在选择第一个表中的单元格时,第二个表才应该可见。然后第二个表包含在第一个 TableView 中选择的单元格的子项。两个 TableView 都连接到它们在 .h 文件中的属性。 Two tableviews inside the viewcontroller (storyboard)

viewcontroller 本身连接到 FoodAddViewController.h 和 FoodAddViewController.m 文件。在 FoodAddViewController.h 文件中,我有:

#import <UIKit/UIKit.h>

@class FoodAddViewController;


@interface FoodAddViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) IBOutlet UITableView *Categorien;
@property (strong, nonatomic) IBOutlet UITableView *Invulling;

- (IBAction)cancel:(id)sender;

@end

对于 FoodAddViewController.m,我有:

@interface FoodAddViewController ()
{
NSArray *CategoryLabel;
NSMutableArray *elementen;
}

@end

@implementation FoodAddViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.Categorien.layer.transform = CATransform3DRotate(CATransform3DIdentity,-1.57079633,0,0,1);
self.Categorien.frame=CGRectMake(0,200, 700,234);
[self.Invulling setHidden:TRUE];
self.Invulling.layer.transform = CATransform3DRotate(CATransform3DIdentity,-1.57079633,0,0,1);
self.Invulling.frame=CGRectMake(0,200, 700,234);
self.Categorien.dataSource = self;
self.Categorien.delegate = self;
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"categorie" ofType:@"txt"];
NSString *content = [NSString stringWithContentsOfFile:filePath
encoding:NSMacOSRomanStringEncoding
error:NULL];
NSArray * categories = [content componentsSeparatedByString:@"\n"];
CategoryLabel = categories;
}
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(self.Categorien==tableView) {
return CategoryLabel.count;
}
if(self.Invulling==tableView) {
return elementen.count;
}
return 0;
}

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(self.Categorien==tableView) {

static NSString *CellIdentifier = @"Cell";
CustomCell *Cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!Cell) {
Cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
Cell.layer.transform = CATransform3DRotate(CATransform3DIdentity,1.57079633,0,0,1);
Cell.frame=CGRectMake(0,0,234,150);

Cell.textLabel.text = [CategoryLabel objectAtIndex:indexPath.row];

return Cell;
}
if(self.Invulling==tableView) {
static NSString *CellIdentifier = @"DetailCell";
CustomCell *Cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!Cell) {
Cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
Cell.layer.transform = CATransform3DRotate(CATransform3DIdentity,1.57079633,0,0,1);
Cell.frame=CGRectMake(0,0,234,150);

Cell.textLabel.text = [elementen objectAtIndex:indexPath.row];

return Cell;
}
return NULL;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 200;
}

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.Invulling.dataSource = self;
self.Invulling.delegate = self;

elementen = [[NSMutableArray alloc]init];
if(self.Categorien==tableView) {
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
NSString *cellText = selectedCell.textLabel.text;
PFQuery *query = [PFQuery queryWithClassName:cellText];
[query selectKeys:@[@"Naam"]];
NSArray *result = [query findObjects];
for (PFObject *object in result) {
NSString *naam = object[@"Naam"];
if(![elementen containsObject:naam]) {
[elementen addObject:naam];
}
}
}
[self.Invulling setHidden:FALSE];
[self.Invulling reloadData];
}
end

现在,问题是 reloadData 方法无法正常工作。例如:如果我按下第一个表格 View (Categorien)中的第一个单元格,则什么也不会发生。但是,当我单击另一个单元格时,第二个表格 View (Invulling) 会加载第一个单元格的结果。

最佳答案

你必须使用 didSelectRowAtIndexPath 而不是 didDeselectRowAtIndexPath 方法

再看看一些调试教程,你应该知道方法不是如果添加了断点则被调用

关于iOS : reloadData not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22424827/

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