UITableView не вставляет новую строку - PullRequest
0 голосов
/ 01 сентября 2010

Я пытаюсь обновить свой UITableView, и следующая реализация не работает.Мне интересно, что я делаю что-то не так?

NSDictionary *newContact = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:@"Name", @"Phone", nil]  forKeys: [NSArray arrayWithObjects:strName, strPhone, nil]];
[arrQuickDialContacts addObject:newContact];

NSLog(@"Returned %@ with phone %@\nNew Count: %d", strName, strPhone, [arrQuickDialContacts count]);

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:([arrQuickDialContacts count] - 1) inSection:0];
NSArray *indexPaths = [NSArray arrayWithObject:indexPath];

[objQuickDialTableView beginUpdates];
[objQuickDialTableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];
[objQuickDialTableView endUpdates];

Вот мои методы делегата для UITableView:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    // How many rows?   
    return [arrQuickDialContacts count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    // See if we have any cells available for reuse
    UITableViewCell *objCell = [tableView dequeueReusableCellWithIdentifier:@"QuickDialCell"];
    if (objCell == nil) {

        // No reusable cell exists, so let's create a new one
        objCell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: @"QuickDialCell"];
    }

    // Give it data
    NSDictionary *objRow = [arrQuickDialContacts objectAtIndex: [indexPath row]];
    objCell.textLabel.text = [objRow valueForKey:@"Name"];

    // Return the created cell
    return objCell;

}

И, наконец, мой viewDidLoad заполняет начальное содержимое массива:

- (void)viewDidLoad {

    // Load the quick dial contacts
    NSString *strPlist = [[NSBundle mainBundle] pathForResource:@"QuickDialContacts" ofType:@"plist"];
    arrQuickDialContacts = [[NSMutableArray alloc] initWithContentsOfFile: strPlist];

    [super viewDidLoad];
}

Спасибозаранее!

1 Ответ

0 голосов
/ 01 сентября 2010

нужно позвонить [tableView reloadData];

На самом деле есть похожий вопрос с более подробной информацией

Невозможно обновить UITableView

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