UITableView заполняет КАЖДЫЙ ДРУГОЙ запуск - PullRequest
0 голосов
/ 07 мая 2010

У меня проблема, которую я не могу понять до конца.

На мой взгляд, загрузил код, я создаю массив и пытаюсь заполнить таблицу. По какой-то причине он заполняет данные КАЖДОЕ ДРУГОЕ время запуска приложения.

Я помещаю логи в viewDidLoad, который работает так же, как и viewWillAppear, и выводит правильное количество для массива.

Кроме того, специфические методы UITableView вызываются, когда он работает, и они просто не вызываются, когда он не работает. Я не могу понять корень этой проблемы.

Опять же, это происходит ровно в 50% случаев. Нет динамических данных, которые могли бы сработать или что-то в этом роде.

#import "InfoViewController.h"

@implementation InfoViewController

- (void)viewDidLoad
{
    NSLog(@"Info View Loaded"); // This runs

    infoList = [[NSMutableArray alloc] init];
    //Set The Data //Theres 8 similar lines
    [infoList addObject :[[NSMutableDictionary alloc] initWithObjectsAndKeys: @"Scrubbed", @"name", @"scrubbed", @"url", nil]];

    NSLog(@"%d", [infoList count]); // This shows the count correctly every time

    [super viewDidLoad];
}

-(void) viewWillAppear:(BOOL)animated
{
    NSLog(@"Info Will Appear"); // This Runs
}

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
  // This WILL NOT RUN when it doesnt work, and DOES show the count when it does run
    NSLog(@"Counted in numberOfRowsInSection %d", [infoList count]);
    return [infoList count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"ROW");
    static NSString *CellIdentifier = @"infoCell";  

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;   
    cell.textLabel.text = [[infoList objectAtIndex:indexPath.row] objectForKey:@"name"];

    return cell;
}


@end

1 Ответ

0 голосов
/ 07 мая 2010

Вам необходимо вызвать метод reloadData tableView в конце viewDidLoad.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...