gpt4 book ai didi

ios - 一个 UIViewController 中的自定义单元格表格 View 和默认 UITableView

转载 作者:行者123 更新时间:2023-11-29 03:12:20 25 4
gpt4 key购买 nike

我有一个带有两个 UITableView 的 UIViewController,一个自定义单元格 XIB tableview 和另一个默认动态 tableview。自定义单元格 tableview 触发它的委托(delegate),但另一个 table view 没有。这是我的代码

@interface Question : UIViewController<UITableViewDataSource,UITableViewDelegate>

和.m

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if(tableView == _similarTable)
{
tableCell =(SimilarQuestion *)[_similarTable dequeueReusableCellWithIdentifier:@"similarTable"];

if(tableCell == nil)
{
tableCell = [[[NSBundle mainBundle]loadNibNamed:@"SimilarQuestion" owner:self options:Nil]objectAtIndex:0];

}
if(finalAskerArray!=nil && finalQuesArray.count >0)
{
tableCell.questionText.text= [finalQuesArray objectAtIndex:indexPath.row];
tableCell.lblAsker.text=[finalAskerArray objectAtIndex:indexPath.row];
}
return tableCell;
}
else
{
NSLog(@"==>Hit");
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"categoryTable"];
if (cell == nil)
{
cell = [[[NSBundle mainBundle]loadNibNamed:@"categoryTable" owner:self options:nil]objectAtIndex:0];
}
if(popCategoryArray != nil && popCategoryArray.count >0)
{
cell.textLabel.text = [popCategoryArray objectAtIndex:indexPath.row];
}
return cell;
}
}

然后我在点击一个按钮时调用默认的表格 View ,点击按钮的代码如下

-(IBAction)catBtnPressed:(id)sender{if(categoryArray.count !=0)    {
popCategoryArray = categoryArray;
categoryView = [[UIView alloc]initWithFrame:CGRectMake(0.0, 0.0, 320 , 548)];
categoryTable.delegate = self;
categoryTable.dataSource =self ;
[UIView transitionWithView:categoryView duration:2.0
options:UIViewAnimationOptionTransitionFlipFromTop
animations:^{
[self.view addSubview:categoryView];
} completion:NULL];

categoryTable = [[UITableView alloc]initWithFrame:CGRectMake(0.0, 0.0, 320, 240)];
[categoryTable reloadData];
[categoryView addSubview:categoryTable];
[self.view addSubview:categoryView];

}

[categoryTable reloadData] 从不调用委托(delegate)。我哪里错了?

最佳答案

在您的代码中,您在设置 categoryTable 之前设置了 categoryTable.delegate。很难弄清楚这是什么意思,但这似乎不对。

从您的代码中摘录一些内容,不清楚 categoryTable 应该在此处设置什么,您在哪里设置委托(delegate):

categoryTable.delegate   = self;

几行之后,您将 categoryTable 设置为一个新对象并将其添加到 View 中:

categoryTable  = [[UITableView alloc]initWithFrame:CGRectMake(0.0, 0.0, 320, 240)];
[categoryTable reloadData];
[categoryView addSubview:categoryTable];

因此,对于 UITableView 的实例,您尚未在调用 reloadData 时设置委托(delegate)。

关于ios - 一个 UIViewController 中的自定义单元格表格 View 和默认 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22126907/

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