2014-02-17 5 views
0

Я делаю приложение, которое включает UITableView. Я добавил TableView в viewController. Это мой ViewController.hUITableView не показывает содержимое NSArray

#import <UIKit/UIKit.h> 

@interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> 
@property (weak, nonatomic) IBOutlet UITableView *tableview; 

@end 

И следующий мой ViewController.m

#import "ViewController.h" 

@interface ViewController() 

@end 
@implementation ViewController 
{ 
NSArray *tabledata; 
} 

@synthesize tableview; 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
tabledata = [NSArray arrayWithObjects:@"Egg Benedict", @"Mushroom Risotto", @"Full Breakfast", @"Hamburger", @"Ham and Egg Sandwich", nil]; 
tableview.delegate = self; 
// Do any additional setup after loading the view, typically from a nib. 
} 

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
return [tabledata count]; 
} 

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
return 150.0; 
} 
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
static NSString *simpleTableIdentifier = @"SimpleTableItem"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 

if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; 
} 
cell.textLabel.text = [tabledata objectAtIndex:indexPath.row]; 
return cell; 
} 

- (void)didReceiveMemoryWarning 
{ 
[super didReceiveMemoryWarning]; 
// Dispose of any resources that can be recreated. 
} 

@end 

Когда я бегу эту программу она показывает мне таблицу, но не имея каких-либо данных, а также количество строк не равно 5. Пожалуйста, помогите мне. Заранее спасибо

+1

вам не хватает tableview.datasource = сам; – Pawan

+0

Спасибо большое :) –

ответ

1

модифицированный код viewdidload

tabledata = [NSArray arrayWithObjects:@"Egg Benedict", @"Mushroom Risotto", @"Full Breakfast", @"Hamburger", @"Ham and Egg Sandwich", nil]; 
tableview.delegate = self; 
tableview.dataSource = self; 
+0

Спасибо, это работает :) –

+0

@SumitKumar ваш приветствуем. – Pawan

+0

Если это решило вашу проблему, не забудьте принять ответ. – Forrest

Смежные вопросы