1

I have a tableview inside a popover in my main view which is a web browser. Whenever the user visits a web page I want it to add the page to a list of recently visited websites. I have the code set up to add the URL as a string to the array that is the data source for the table view. The table view only shows the first site visited and won't show anything past that. However I know the sites are being added to the array because the array shows the Sites using NSLog statements after being added. However they still won't show up in the table. Can anyone help me?

EDIT:

 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

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

    // Return the number of rows in the section.
    return [recentlyVisitedUrls count];
}
2
  • 1
    Are you calling [tableView reloadData]? Commented Jan 13, 2012 at 21:12
  • Yes but it deletes data that was there previously Commented Jan 13, 2012 at 22:06

4 Answers 4

2

Also make sure you are returning the correct length of your array from – tableView:numberOfRowsInSection:

Sign up to request clarification or add additional context in comments.

Comments

2

Try

[tableView reloadTable];

after you add the new data.

3 Comments

when i do this i have to put it before the data is added and it comes up as [tableView reloadData]; also data that was there before disappears
Show your delegate methods for numberOfSectionsInTableView:, numberOfRowsInSection: and cellForRowAtIndexPath:. Put in your original question for formatting purposes.
ive fixed it. i had to reload the data again after updating the numberOfRowsInSection:
0

If you wan't animated updating, you can call:

[self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]

If you need animation, it will be better read: Table View Programming Guide for iOS, you need Batch insert… part.

Comments

0

If you have a large table, [tableView reloadData] is probably not ideal. It'll also will reset your view to the beginning of the table, which may or may not be desirable. You might try something like this:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:_model.recordCount - 1 inSection:0];
[_tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];
[_tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];

BTW, _model is the data delegate class for the table in the example.

Also, make sure the data delegate updates it's total count correctly before you insert, or your app will crash on the insertRowsAtIndexPaths.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.