2016-11-03 6 views
1
- (void)viewDidLoad { 
    [super viewDidLoad]; 
    menuArray=[[NSMutableArray alloc]initWithObjects:@"Address",@"Restaurants",@"Deals",@"Orders",@"Account",@"Address Book",@"Settings",@"Live Chat",@"Info",nil]; 
    tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, menuSubView.frame.size.height, self.view.frame.size.width-80, self.view.frame.size.height-menuSubView.frame.size.height)]; 
    tableView.delegate=self; 
    tableView.dataSource=self; 
    [self.view addSubview:tableView]; 
} 

とfollows-私はプログラムを実行するときしかし、私は必要に応じて、テーブルビューを見ることができていますfollows-

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return menuArray.count; 
} 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *[email protected]"Cell4"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reusableIdentifier]; 
    if(cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reusableIdentifier]; 
    } 
    cell.textLabel.text=[menuArray objectAtIndex:indexPath.row]; 

    return cell; 
} 

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    return 70; 
} 

などの他の方法として、プログラムでテーブルビューを作成しました。しかし、私はそれをスクロールすると、テーブルのデータが消えて、空白のテーブルビューだけが残っています。誰でも助けてくれますか?前もって感謝します。

+0

がcellForRowAtIndexPathでブレークポイントを入れて、あなたがよくやったようだ –

+0

をリロードした後、テーブルビューがどのように動作しているか、テーブルをスクロールした後に確認し、あなたのラベルの色は白ですか? –

+0

cellForRowAtIndexPathにブレークポイントを置こうとしましたが、テーブルが完全に作成されるまでうまく動作します。一度テーブルをリロードすると、ポインタはcellForRowAtIndexPathに戻りません。 –

答えて

0

- >上記の回答に感謝します。

- > "cellForRowAtIndexPath"メソッドでこの行を試してください...!

- >ときどき起こります。私はこの問題を過去に解決しました。それがあなたにとって有益だと思います。

UITableViewCell *cell = [self.tblView dequeueReusableCellWithIdentifier:@"Cell4" forIndexPath:indexPath]; 
+0

私もこれを試してみましたが、問題は、dequeueReusableCellWithIdentifier :: forIndexPathを使用すると、「識別子のクラスまたはペン先を登録する必要があります」というエラーが表示されます。私はそのエラーについて読んで、削除:forIndexPathがそのエラーのために動いたが、私はこの問題が出始めたことに気づいた。 –

関連する問題

 関連する問題