gpt4 book ai didi

ios - TableView 不显示标签 ios

转载 作者:行者123 更新时间:2023-11-29 10:23:42 25 4
gpt4 key购买 nike

我正在 NSObject 调用中添加一个表,这样我就可以创建自定义 View 。但是正在调用 tableView cellForRowAtIndexPath 但未显示标签。我已经获取了一个 View 并在该 View 上添加了表格,并在父类(super class)中添加了该 View 。

代码如下:

- (id)initWithFrame:(CGRect)frame
{
self = [super init]; //calls init because UIResponder has no custom init methods
if (self){
[self allocViewWithFrame:frame];
}
return self;
}

-(void)allocViewWithFrame:(CGRect)frame{
view = [[UIView alloc]initWithFrame:frame];

TableViewChat =[[UITableView alloc]initWithFrame:CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height)];
TableViewChat.delegate = self;
TableViewChat.dataSource = self;
[view addSubview:TableViewChat];
dispatch_async(dispatch_get_main_queue(), ^{
[TableViewChat reloadData];
});

}

#pragma mark- tableView delegate and data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 144.0f;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//#warning Incomplete implementation, return the number of rows
return 5;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SimpleTableCell"];

if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"SimpleTableCell"];

}

cell.textLabel.text = @"Cell";
return cell;

}

最佳答案

只需编辑 cellForRowatIndexPath

-(UITableViewCell *)tableView:(UITableView *)tableView   cellForRowAtIndexPath:(NSIndexPath *)indexPath
{


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

cell.titleLabel.text = @"First"

return cell;
}

关于ios - TableView 不显示标签 ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33476175/

25 4 0