gpt4 book ai didi

iphone - UITableView只有向上滚动后才会显示

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

我有一个 Storyboard,其中有一个 UIView 和一个 UITableView。 UITableView 具有自定义单元格(带有 xib 的 UITableViewCell)。当我运行应用程序时,仅显示表格的第一行,表格的其余部分被隐藏。这些行在屏幕上看不到,但它们按预期响应用户交互。

其余单元格仅在表格向上滚动后才会显示。

可能是什么问题?

这是带有表格的 UIView 的代码:

@implementation EldersTableViewController
@synthesize items;
@synthesize tableView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
EldersDataHendler *edh = [[EldersDataHendler alloc]init];
NSMutableArray *itemsFromPList = [edh dataForTableFrom:[NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"eldersData" ofType:@"plist"]]];
self.items = itemsFromPList;
[edh release];
edh=nil;

}

- (void)viewDidUnload
{
[super viewDidUnload];
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}


- (IBAction)didPressBackButton:(UIButton *)sender {
[self.view removeFromSuperview];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.items count];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}

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

SEObject *cellInfo = [self.items objectAtIndex:indexPath.row];
EldersItemCell* cell = (EldersItemCell*)[tableView dequeueReusableCellWithIdentifier:@"EldersItemCell"];
if (cell == nil) {

NSArray* topObjects = [[NSBundle mainBundle] loadNibNamed:@"EldersItemCell" owner:self options:nil];

for (id obj in topObjects){
if ([obj isKindOfClass:[EldersItemCell class]]){
cell = (EldersItemCell*)obj;
break;
}
}


}
[cell setObject:cellInfo];
return cell;
}
#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SEObject *cellInfo = [self.items objectAtIndex:indexPath.row];
if (!eldersDetailsViewController){
eldersDetailsViewController = [[self.storyboard instantiateViewControllerWithIdentifier:@"elderDetailsVC"] retain];
}
eldersDetailsViewController.seObject = cellInfo;
[self.view addSubview:eldersDetailsViewController.view];
}

- (void)dealloc {
[eldersDetailsViewController release];
[tableView release];

[super dealloc];
}
@end

提前致谢,旅达

最佳答案

首先为您的单元格设计创建一个对象类,然后将其导入到您的 .m 文件中。然后尝试像这样正确连接 TableView 委托(delegate)和数据源

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

static NSString *CellIdentifier = @"Displayfriendscell";
Displayfriendscell *cell = (Displayfriendscell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[Displayfriendscell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
// Configure the cell...
[[cell viewWithTag:121] removeFromSuperview];
[[cell viewWithTag:151] removeFromSuperview];
friend *user = [sortedFriendsArray objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryNone;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
//cell.nameLabel.text = user.contactNAame;
cell.nameLabel.text = user.friendName;
//cell.nameLabel.text =[[sortedFriendsArray objectAtIndex:indexPath.row] objectForKey:@"name"];
//user.friendName=[[sortedFriendsArray objectAtIndex:indexPath.row] objectForKey:@"name"];
NSLog(@"name is%@",cell.nameLabel.text);

return cell;

}

关于iphone - UITableView只有向上滚动后才会显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10795733/

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