Я делаю приложение, которое включает 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. Пожалуйста, помогите мне. Заранее спасибо
вам не хватает tableview.datasource = сам; – Pawan
Спасибо большое :) –