UITableView с данными из массива - PullRequest
0 голосов
/ 18 января 2012

У меня есть UIViewController с 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 У меня есть и источник данных, и делегат, связанный с владельцем файла.

Ответы [ 3 ]

1 голос
/ 18 января 2012

Установите делегат и источник данных для вашего tableView. это будет работать.

0 голосов
/ 18 января 2012

Проверьте консоль на наличие ошибок и сообщите нам.

0 голосов
/ 18 января 2012

Где вы установили свой массив, перезагрузите таблицу ...

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

Измените 'myTable' на имя вашей таблицы, которое вам нужно будет добавить в заголовок в качестве переменной и подключить через IB, если вы его используете.

...