2012-05-29 3 views
3

У меня есть раскадровка с UIView и UITableView в ней. UITableView имеет пользовательские ячейки (UITableViewCell с xib). Когда я запускаю приложение, отображается только первая строка таблицы, остальная часть таблицы скрыта. Строки не видны на экране, но они реагируют на взаимодействие пользователя, как ожидалось.UITableView проявляется только после прокрутки вверх

Остальные ячейки отображаются только после прокрутки стола вверх.

В чем может быть проблема?

Вот код для 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 

Заранее спасибо, Люды

+0

UITableView может не быть чашкой чая каждого, но, конечно же, не оскорблен ?! ;) Я подозреваю, что ваши клетки не «раскрыты». – arooaroo

+1

Что происходит, когда вы используете стандартный канонический код для cellForRowAtIndexPath, используя стандартные UITableCells, а не ваши пользовательские представления? Это просто способ устранения проблемы с EldersItemCell или с вашей раскадровки. – arooaroo

+0

Нет, не оскорблено :), только не раскрыто :) Вы правы! Проблема должна быть в пользовательской ячейке, потому что стандартный UITableCells показывает, что это хорошо. – Luda

ответ

0

Проблема решена! Спасибо много дорогой arooaroo. Было что-то с пользовательской ячейкой с xib. Таким образом, я создал программную программу Table View Cell. Вот хороший tutorial

0

первый раз создать класс объектов для вашего дизайна ячейки, а затем импортировать его в файле .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; 

}