gpt4 book ai didi

ios - 自定义 UITableCell 不工作

转载 作者:行者123 更新时间:2023-11-28 22:51:53 26 4
gpt4 key购买 nike

我搜索了太多,尝试了很多想法,但我无法让它发挥作用。

我有一个 View Controller ,在那个 Controller 中我有一个带有自定义单元格的 TableView 。我连接了网点、数据源和委托(delegate),但是当我运行项目时,而不是我的自定义单元格。显示了 UITableCell,但也不显示数据。这是我的 .h 和 .m 文件

#import <UIKit/UIKit.h>
@class SelectMutantCell;
@interface MutantViewController : UIViewController <UITableViewDataSource,UITableViewDelegate>{
UITableView *tableView;
IBOutlet SelectMutantCell *mutantCell;
}

@property (nonatomic, weak) IBOutlet UITableView *tableView;
@property (nonatomic, weak) SelectMutantCell *mutantCell;

- (IBAction)cancel:(id)sender;

@end

这是我的 .m 文件

    @implementation MutantViewController

@synthesize tableView = _tableView;
@synthesize mutantCell = _mutantCell;

NSArray *mutants;

- (void)viewDidLoad
{
[super viewDidLoad];
//mutants = [mutants initWithObjects:@"Keko",@"HEHE",@"PEPE", nil];
UINib *cellNib = [UINib nibWithNibName:@"SelectMutantCell" bundle:nil];
[self.tableView registerNib:cellNib forCellReuseIdentifier:@"SelectMutantCell"];

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = @"SelectMutantCell";

SelectMutantCell *cell = (SelectMutantCell *)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];

NSLog(@"---");

cell.nameLabel.text = @"Hehe"];
cell.descriptionLabel.text = @"hhe";



return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 3;
}

NSLog(@"---") 用于调试,运行时出现。问题在

cell.nameLabel.text = @"Hehe"];
cell.descriptionLabel.text = @"hhe";

这个 block ,如果我写 cell.textLabel.text = "test"它可以工作,但我需要显示我的自定义单元格。

任何帮助将不胜感激..

最佳答案

插入 if(cell==nil){} 循环

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = @"SelectMutantCell";
SelectMutantCell *cell = (SelectMutantCell *)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[SelectMutantCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSLog(@"---");
cell.nameLabel.text = @"Hehe"];
cell.descriptionLabel.text = @"hhe";
return cell;
}

关于ios - 自定义 UITableCell 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11793801/

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