gpt4 book ai didi

ios - UITable 不调用委托(delegate)方法

转载 作者:行者123 更新时间:2023-11-28 19:13:18 25 4
gpt4 key购买 nike

我有一个 UIView,我在其中初始化一个表并将 UIView 设置为委托(delegate)。我的 .h 文件:

...
@interface vOperatingRooms : UIView <UITableViewDataSource, UITableViewDelegate>{
...

表初始化在一个名为 showSelf 的方法中,我已经测试了电视显示的位置,这是初始化:

...
dataTable = [[UITableView alloc] init];
CGRect dataTableFrame = dataTable.frame;
dataTableFrame.origin.x = (self.frame.size.width/2)-100;
dataTableFrame.origin.y = 115.0;
dataTableFrame.size.width = 200.0;
dataTableFrame.size.height = 200.0;
dataTable.frame = dataTableFrame;
dataTable.alpha = 0.0;
dataTable.tag = 33;
dataTable.delegate = self;
dataTable.dataSource = self;
[self addSubview:dataTable];
...

还有另一种从 plist 中读取以构建表的数据源的方法:

...
//set up the directory path
NSString* pathToProjectFolder = [NSString stringWithFormat:@"Projects/%@", projectNumber];
//set up the file path
NSString* ORDataFilePath = [NSString stringWithFormat:@"%@/ORData.plist", pathToProjectFolder];

//check to make sure the project directory exists and the ORData.plist file
[fileManager createDirectory:pathToProjectFolder];
[fileManager createPlist:ORDataFilePath];

//pull the data from the file
NSDictionary* ORData = [fileManager readPlist:ORDataFilePath];
ORNames = [[NSMutableArray alloc] init];

for(NSString* thisOR in ORData){

if (![thisOR isEqualToString:@"File Name"]) {
[ORNames addObject:thisOR];
}
}

//fade in table
//fade in
[UIView animateWithDuration:0.25 delay:0.0 options:UIViewAnimationOptionCurveEaseOut

animations:^{
dataTable.alpha = 1.0;
}

completion:^ (BOOL finished) {
}

];

...

我已经记录了结果,并且正在获取我正在寻找的数据 - 这是 NSArray ORNames 的控制台:

2012-12-06 15:01:23.370 IntegrationSiteReport[18697:c07] (
Test4,
Test6
)

这是委托(delegate)方法:

#pragma mark Table View Management
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

return ORNames.count;
NSLog(@"%i", ORNames.count);
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

cell.textLabel.text = [ORNames objectAtIndex:indexPath.row];
cell.textLabel.textColor = [colorManager setColor:66.0 :66.0 :66.0];
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:20.0];
return cell;
}

我知道它们没有被调用,因为它们内部没有任何日志记录。我在这里缺少什么吗?

最佳答案

什么时候调用 showSelf?如果它在 View 加载层次结构之后,您可能只需要添加一个 [dataTable reloadData]; 作为 showSelf 的最后一行,虽然不确定。

关于ios - UITable 不调用委托(delegate)方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13751615/

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