3

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

よろしくお願いします、ルダ

4

2 に答える 2

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;

}
于 2012-05-29T12:30:49.880 に答える
0

問題が解決しました!どうもありがとうarooaroo。xibのカスタムセルに何かがありました。そこで、プログラムでカスタムのテーブルビューセルを作成しました。これは素晴らしいチュートリアルです

于 2012-05-31T10:16:05.977 に答える