2012-01-18 10 views
0

UIViewControllerにはUITableViewがあります。私は今配列からの私のデータでこのテーブルビューをいっぱいにしたい。しかし、問題は何も表示されないということです。配列からのデータを持つUITableView

これは私の実装ファイルです:

#import "MenuViewController.h" 

@implementation MenuViewController 
@synthesize menuArray; 

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

- (void)didReceiveMemoryWarning 
{ 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.menuArray = [[NSArray alloc] initWithObjects:@"Catalogus",@"Wishlist", nil]; 
    // Do any additional setup after loading the view from its nib. 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    self.menuArray = nil; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return YES; 
} 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
} 
// Customize the number of rows in the table view. 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [self.menuArray count]; 
} 
// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    // Configure the cell. 
    cell.textLabel.text = [self.menuArray objectAtIndex:indexPath.row]; 

    return cell; 
} 
@end 

これは私のヘッダファイルです。

#import <UIKit/UIKit.h> 

@interface MenuViewController : UIViewController <UITableViewDelegate,UITableViewDataSource> 
{ 
    NSArray *menuArray; 
} 
@property (nonatomic,retain) NSArray *menuArray; 

@end 

私のXibファイルでは、データソースとデリゲートの両方がファイル所有者に接続されています。あなたの配列を設定

+1

とは何ですか? –

+0

何も表示されません。 – steaphann

+0

ヘッダーファイル全体ですか?もしそうなら、あなたは 'IBOutlet UITableView * yourTableview;を作成する必要があります。 xibに接続してください – Novarg

答えて

0

は、...テーブルをリロード

self.menuArray = [[NSArray alloc] initWithObjects:@"Catalogus",@"Wishlist", nil]; 
[myTable reloadData]; 

あなたが変数としてヘッダに追加し、経由で接続する必要がありますあなたのテーブルの名前に変更し「mytableは」あなたがそれを使用しているならば、IB。

+0

@ user1155884が提供しているのと同じコードを使用しました。ペン先では、私はファイルの所有者のデータソースとデリゲートに設定されたテーブルビューを持っていた。それはうまく動作します。 – nithinbhaktha

0

エラーがありましたら、私たちにご連絡ください。

+0

いいえ、エラーはありません – steaphann

1

テーブルビューのデリゲートとデータソースを設定します。 それが動作します。

+0

これは今、うまく動作します! – steaphann

関連する問題