Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UITableView仅在向上滚动后才显示_Iphone_Objective C_Xcode_Uitableview - Fatal编程技术网

Iphone UITableView仅在向上滚动后才显示

Iphone UITableView仅在向上滚动后才显示,iphone,objective-c,xcode,uitableview,Iphone,Objective C,Xcode,Uitableview,我有一个带有UIView和UITableView的故事板。UITableView具有自定义单元格(带有xib的UITableViewCell)。 当我运行应用程序时,只显示表的第一行,其余部分隐藏。 这些行在屏幕上看不到,但它们按照预期响应用户交互 只有在向上滚动表格后,才会显示其余单元格 有什么问题吗 以下是UIView与表格的代码: @implementation EldersTableViewController @synthesize items; @synthesize tableVi

我有一个带有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
提前感谢,,
Luda

首先,只需为单元格设计创建一个对象类,然后将其导入.m文件中。然后像这样尝试,并正确连接表视图委托和数据源

- (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;

}

问题解决了!非常感谢亲爱的arooaroo。自定义单元格和xib有点关系。因此,我以编程方式创建了一个自定义表视图单元格。这里有一个很好的

UITableView可能不是每个人都喜欢的,但肯定不是被人唾骂的?!;)我怀疑您的单元格没有“显示”。如果使用标准UITableCells而不是自定义视图来使用cellForRowAtIndexPath的标准规范代码,会发生什么?这只是一种消除问题的方法,无论是关于EldersItemCell还是关于你的故事板。不,不是辱骂:),只是没有透露:)你是对的!该问题必须与自定义单元格有关,因为标准UITableCells显示良好。问题已解决!非常感谢亲爱的arooaroo。自定义单元格和xib有点关系。因此,我以编程方式创建了一个自定义表视图单元格。这里有一个很好的教程:@Luda,以防你感兴趣(因为我知道这里没有直接的消息):你的个人资料中的LinkedIn链接断了。