I am trying to reload a tableView from a different class. After some NSLogs in the console, my data is being altered but not changed. Below is some code:
SecondViewController.m
开发者_如何学CRootViewController *test = [[RootViewController alloc] init];
// Set up database connection
NSString *myDB = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"flashpics.db"];
database = [[Sqlite alloc] init];
[database open:myDB];
[database executeNonQuery:@"INSERT INTO albums (id, name, connections) VALUES (?,?,'No Connections')", theID, theName];
[test.listOfItems addObject:theName];
RootViewController *controller = [[RootViewController alloc] init];
[controller.tableView reloadData];
[self dismissModalViewControllerAnimated:YES];
Can you please help me solve probably one of the easiest questions that exists?
Thanks, Coulton
EDIT#1: NSLogs display the following. Could this do with anything?
__NSAutoreleaseNoPool(): Object 0x5883000 of class UITableView autoreleased with no pool in place - just leaking
EDIT #2: Added more code to the SecondViewController.m
Edit #3: For some reason it's not working.
SecondViewController.m
RootViewController *controller = [[RootViewController alloc] init];
[RootViewController refreshTableView];
RootViewController.m
- (void) refreshTableView {
[self.tableView reloadData];
NSLog(@"Refreshing TableView - %@", listOfItems);
}
I Inserted 'neato' in the array. Then I called reloadTableView in the SecondViewController.m to RootViewController.m. I did get an output, but it didn't update the tableView. Below is the NSLog.
Refreshing TableView - (
"Default Album",
"Hello.",
"This is cool!",
hi,
neato
)
P.S. I don't get results, but I do get stuff I programmed it to say through a NSLog.
You initialize your RootViewController twice. Twice too many I imagine. You need to find a reference to your view controller and add the item to it's listOfItems. Then call reloadData
on that controller's UITableView.
the question is why?
or what do you really want to do?
Your code doesn't make much sense, you are creating a new instance of RootViewController, and you are calling reloadData before the tableView has showed you some data. No need to reload before the tableview has data. But I think you want to reference the old instance instead of the new one you've just created
If this is what I think it is, a Navigation Based project where SecondView gets created in tableView:didSelectRowAtIndexPath:
, and then pushed to the navigationcontroller you should try to call [self.tableView reloadData];
in - (void)viewWillAppear:(BOOL)animated
of the RootViewController
But I'm just guessing (although I'm pretty good at this) because your code makes no sense. No need to reload the tableview at this stage, because the tableview doesn't have any data.
精彩评论