I have an Xcode app that creates a tableview and then populates this with data from an sqlite database, this works perfectly and allows me to push data to a new view and delete etc,
This tableview is the first view loaded on a tab bar controller. The problem arises when i move to another view on the same controller, i.e. create an athlete, in this view i can add a new athlete to the database (which works fine) but when i go back to the tableview on the tab bar controller, the table is the same, i have to log out and log back in to see the change in the table,
I have tried [self.tableView reloadData] in the viewWillAppear function but this does nothing. I know that the function is getting called as i have placed an NSLog in their just for peace of mind.
I have found what i think may be the solution on here but i cant get it to work!
viewWillAppear, viewDidAppear not being called, not firing
i will post my code below and a screen shot of the storyboard as im convinced it is my poor way of setting up controllers that has caused this error. Any help would be much appreciated as i am now at the meltdown stage :D
-(void)viewWillAppear:(BOOL)animated {
//[super viewWillAppear:animated];
//[self.tabBarController viewWillAppear:animated];
[self.tableView reloadData];
NSLog(#"i just ran viewwillAppear");
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
athleteObject *athObj3 = [athletes objectAtIndex:indexPath.row];
athleteIdDelete = athObj3.athId;
[self openDatabase];
[self deleteAthleteFromDataBase];
[athletes removeObjectAtIndex:indexPath.row];
[tableView reloadData];
}
reloadData works in my commitEditing function (this updates the tableview when i delete an entry via a swipe)
any help would be much appreciated, il post the screen shot below.
(cant figure out how to load a screenshot if its even possible)
It looks like athletes (a NSMutableArray I assume) is not being updated in viewWillAppear. Have you tried running the selector that populates the array from the database before calling reloadData?
Hope that helps!
I'm assuming you're setting the number of rows/sections in your code based on how many objects are returned from a database.
Set a breakpoint at this method, and get the count each time the compiler breaks. You are probably not getting any objects from the database, and therefore the compiler never runs the rest of the table view dataSource methods.
Related
I have a Storyboard scene which contains an NSTableView with an NSTableViewRow subclass. In this table view row, I have a button which I have wired up to an action in the view controller on the scene.
When the table loads, I am seeing this cryptic error from Xcode and the action never fires when I click the button:
Could not connect action, target class NSNibExternalObjectPlaceholder does not respond to -playVideo:
It looks like the file's owner never gets wired up.
Since these NSTableRowViews get instantiated programmatically, I checked to see if the owner is getting set, and indeed it is:
- (NSView *) tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
...
CombinedHistoryEntryTableCellView *cellView = [tableView makeViewWithIdentifier:#"deviceEvent" owner:self];
...
return cellView;
}
I believe I am experiencing a bug (and I will file a radar later) but I was able to work around the issue by wiring the button up to an action on the CombinedHistoryEntryTableCellView class in IB. Since the code needed to run the action was in the view controller I gave the cell view object a reference to the controller so that it could call it.
Still don't know why that was an issue, though, but if someone else experiences this that is a suitable workaround.
Looking at my iPad app, I have several containerviews. Containerviews enable me to show all four iphone views on a single iPad screen simultaneously. One view, called TrackingViewController, has a UITableView on it (called table) that I want to refresh from a button on a second view controller (MainViewController) which is also visible on the same iPad screen. I call the code
TrackingViewController *trackView = [[TrackingViewController alloc] init];
[trackView.view setNeedsDisplay];
[trackView.table reloadData];
at the end of the IBAction for the button in MainViewController, the data transfers perfectly, but the table itself on TrackingViewController does not visually update to show this data.
If I then manually initiate a completely different modal view controller and dismiss it on TrackingViewController when the app is running on iPad then the data shows up. How do I make the view or data on TrackingViewController automatically update visually when the button is pressed on MainViewController?
iPad Simulator may help.
I also dont understand your question..
The only thing I see is, you want to update two UITableViews but in your code you are only reloading Data of one TableView?!?
[trackView.table reloadData];
[otherTable reloadData];
But I realy dont understand your question....
If your other TableView is in another class, just try something like this...
In TrackingViewController.h:
- (void)refreshMyTable;
In TrackingViewController.m:
- (void)refreshMyTable{
[table reloadData];
}
In your MainViewController.m Action, that should refreshes both Tables:
- (IBAction)theRefreshingAction{
TrackingViewController *trackView = [[TrackingViewController alloc] init];
[trackView refreshMyTable]; //This refreshes Table in trackView
[mainViewTable reloadData]; //This in MainView
}
Ended up using NSNotificationCenter by utilizing the following post:
Calling a function from a different view controller for iphone
In my case, calling a function that only included [table reloadData]; wouldn't work, but calling my performFetch function did (which also called [table reloadData]; at the end of it).
I need help in following scenario.
I am building an app that displays tableview. If the user tap an entry it goes to the detailed screen. In the detail screen, I have a button to delete this entry. It deletes the entry from the data source and dismiss the modal.
But after dismissing the modal, table view data is not refreshing.
If I go back to parent view controller and then again come back to child screen, it refreshes the count.
I read few similar posts and found the following solution.
[tableview reloadData];
Or
[self.tableView reloadData];
In - (void)viewDidAppear:(BOOL)animated of child screen.
But its not refreshing the table view.
Please help.
For completeness, the full implementation would be:
- (void)viewWillAppear:(BOOL)animated
{
// Do stuff like reload the tableview data...
[self.tableView reloadData];
}
If it's not working you have a problem elsewhere in your code.
If the tableview is in the parent viewcontroller, I suggest that placing reloadData: method at viewWillAppear: of the parent.
(void)viewWillAppear:(BOOL)animated
{
[self.tableView reloadData];
}
I'm sure that the method will be called when the detailed viewcontroller dismissed.
Go through this code:
- (void)viewWillAppear:(BOOL)animated
{
[self.tableView reloadData];
}
I have a UITableView that stores the selected row in User Defaults. The tableView is part of a menu structure that may be reloaded during the lifetime of the application, hence I want the persistence between loads. In viewDidLoad, this UserDefault is checked for existence, and I call
NSIndexPath *path = [NSIndexPath indexPathForRow:row inSection:0];
[self.tableView selectRowAtIndexPath:path animated:NO scrollPosition:(UITableViewScrollPositionMiddle)];
This works fine, as expected. However, it doesn't actually select the row, it just highlight's it. If I subsequently call
[self tableView:self.tableView didSelectRowAtIndexPath:path];
I get a crash - "unrecognised selector sent to instance". Why?
[self tableView:self.tableView didDeselectRowAtIndexPath:path] will call YOUR implementation of the deselection method (which is defined in UITableViewDelegate).
You get a crash since you didn't implement it in your delegate.
You should call:
[self.tableView deselectRowAtIndexPath:path animated:NO];
The UITableView works via two delegate protocols, UITableViewDelegate and UITableViewDataSource. The class that defines your UITableView should implement these protocols and you should set the delegate and datasource of the UITableView to "self". You should not call the protocol methods directly which is most likely the reason for your crash.
In order to select a particular row based on your data model (User Default), you will need to set the UITableViewCell selected property to "YES" in the tableView:cellForRowAtIndexPath: for the row that is being rendered.
I recommend going through this tutorial to help you understand UITableView's better.
http://www.iosdevnotes.com/2011/10/uitableview-tutorial/
I am trying to make a drill down table with storyboards in a Tab bar app.
I am having a problem with working out how to get each row in a main table to point to other different tables.
This is the code I have used to detect row selection.
-(void)tableView: (UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *__strong)indexPath {
TableViewController *table = [self.storyboard instantiateViewControllerWithIdentifier:#"table"];
[self.navigationController pushViewController:table animated:YES];
}
How do I proceed please?
The real beauty to UIStoryBoards are the segues.
1. You can link one prototype cell push segue to another different table view controller
2. You can link one prototype cell push segue loop back to itself for drill downs.
[self performSegueWithIdentifier:#"segueID" sender:MyObject];
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([segue.identifier isEqualToString:#"segueID"]) segue.destinationViewController.chosenCell = sender;
}
If the segue is from the cell click, the sender is that of the cell and you can get it's indexpath from the table, and pass new information to the upcoming view controller.
If you want the cell to take various paths when clicked, keep the didSelectRowAtIndexPath and call performSegueWithIndetifier so you can choose left or right.
Tutorial: http://jleeiii.blogspot.com/2012/05/uistoryboard-power-drill-batteries.html
GitHub: http://www.github.com/jllust/UIStoryboardExamples
I was extremely frustrated with this, as the storyboards with tableviews is really not covered ANYWHERE. I literally almost pulled my hair out trying to figure this out. So my frustration is your luck!
Comparing your code to mine, yours looks fine other than the fact that in the initial didSelectRowAtIndexPath: method, you have *_strong, which should not have the _strong part. It should just be like this: (NSIndexPath *)indexPath {
Additionally, be careful in when you are referring to the instantiateViewControllerWithIdentifier in Interface Builder. I accidentally filled out the name of the instance variable under 'TITLE' instead of 'IDENTIFIER'
I hope this helps. I completely understand your frustration.
In your storyboard, if the content is Static Cells, you can ctrl-drag from the specific row to a Navigation Controller. Then connect the Navigation Controller to your next table. Look at this screen shot. http://cl.ly/1V2y0v202y390U0A351x
My guess is that progromatically, you'll need to do something similar, segue to a NavigationController which has a table view controller as it's root view.