Xcode reload complete UITableViewController - xcode

I have a tableviewcontroller with some sections which can be collapsed and expanded.
it is also possible to add new sections to my tableview.
But newly added sections are only visible after closing and reopening the tableview.
Somehow, I need to reload the whole tableview after adding a section.
[tableview reloadData] doesnt work.
So how can I manually reload the complete tableview without closing and reopening
the window? (or at least the user shouldn't notice a close and re-open operation).

I think this should work :
- (IBAction)refreshButton: (id)sender {
[self.tableView reloadData];
}
or it might be this
- (IBAction)refreshButton: (id)sender {
[self reloadTableData];
}
Hope it works!

Related

Why is the NSStatusItem displaying multiple times?

A NSStatusItem has a NSMenu attached, and one of the buttons of the NSMenu opens a NSWindow. Whenever one of these buttons is clicked, the window opens as expected and works properly, but another display of the NSStatusItem is opened.
The NSStatusItem is a clock, so I can see that it is updating correctly. However, the cloned NSStatusItem doesn't have its own menu. If I push the button that makes the window more times, more cloned versions of the NSStatusItem pop up.
Everything works fine except for this.
That's not a whole lot of information to go off of, but there's nothing else I can think of that could potentially help you. I would be happy to provide more information or try something.
EDIT: Every time the button is clicked, awakeFromNib is somehow called, which is why another half-working NSStatusItem happens.
EDIT: Temporary workaround is to put the awakeFromNib method in a dispatch_once.
EDIT: Added method that is triggered when button is clicked, as suggested by #zpasternack
- (IBAction)preferences:(id)sender {
self.windowController = [[NSWindowController alloc] initWithWindowNibName:#"PreferencesWindow"];
[[self windowController] showWindow:self];
}
Is the NSStatusItem contained in the PreferencesWindow nib? That might explain it, since you're loading the nib each time the button is clicked.
Also, is there a reason you need to recreate that window each time the button is clicked? Maybe you could only do it the first time?
- (IBAction)preferences:(id)sender {
if( self.windowController == nil ) {
self.windowController = [[NSWindowController alloc] initWithWindowNibName:#"PreferencesWindow"];
}
[[self windowController] showWindow:self];
}

self.tableView reloadData not working in viewWillAppear

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.

Storyboard UIImagePicker overlay UIButton does not dismiss preview

update 2
viewDidAppear is executed twice, once before and once after, the overlay button is touched. Would a fix be to add a conditional to viewDidAppear which would return control to the calling class? If so, I would appreciated suggestions. Or maybe the very fact that viewDidAppear execute twice suggests another approach to a fix?
update 2
update 1
Maybe the problem is my usage of viewDidAppear and viewDidLoad shown below. Can anyone help, please?
- (void)viewDidAppear:(BOOL)animated
{
self.overlayViewController = [[BSsetupOverlayViewController alloc] initWithNibName:#"BSsetupOverlayViewController" bundle:nil] ;
// as a delegate we will be notified when pictures are taken and when to dismiss the image picker
self.overlayViewController.delegate = self;
[self showImagePicker:UIImagePickerControllerSourceTypeCamera];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
update 1
update 0
Perhaps I was not clear that the difference between the version that does not work and the one that does is that Storyboard is used in the one that does not work. Why would a done button work without Storyboard, but not with, even though only a nib is involved with the overlay?
update 0
The UIButton here was able to dismiss the camera preview, but in my actual app, tapping the UIButton only temporarily dismisses the preview and overlay screen. Immediately the preview returns. I think the problem is with the way I am implementing the delegate to the UIImagePicker, but I may be wrong.
I have created setup.zip here which contains a sample project with the undesirable behavior.
I took this question to the North Atlanta iOS Meetup and suggested that a conditional clause might fix the problem, as I mentioned in update 2 of the question. The founder of the Meetup, Kurt Niemi, quickly showed how to do so by editing the BSsetupViewController class.
First he added a Boolean property to the interface.
#property (nonatomic, assign) BOOL alreadyDisplayed;
Second he added a clause to the viewDidAppear method.
if (self.alreadyDisplayed)
{
self.alreadyDisplayed = FALSE;
[self dismissViewControllerAnimated:NO completion:nil];
return;
}
self.alreadyDisplayed = TRUE;
And last he added a slight unnecessary clause to the viewDidLoad method.
self.alreadyDisplayed = FALSE;
I still wish these steps were unnecessary, but they seem to work.

UIScrollView Not working properly in IOS6

I'm using a simple UIScrollview in a One of my TabBarViews. I want this to work with autolayout so I did some searching I found out the the ViewDidappear method works with autolayot.
The scroller works fine with the viewdidAppear instead of viewDidLoad, but when i switch to another tab without scrolling back to the top it does not release or something.
When I go back to the scrollview tab the scroller is not able to go all the way to the top?
It starts where i left of and scrolls all the lenght from there.
http://tinypic.com/r/24dmys8/6
Start of scroll, when I contiune to scrolldown and switch tab.
http://tinypic.com/r/2e37vb9/6
When I come back from another tab the scroll starts at this point. I think Iit's some kind of release problem... But I can't work out what?!
Here is the code I've used:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.ScrollviewVT2 setContentSize:CGSizeMake(320.0,1440.0)];
[self.ScrollviewVT2 setContentOffset:CGPointZero animated:YES];
}

Tableview not reloading after data change : IOS 5

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];
}

Resources