Stepper not updating - ios

I have two steppers in a ViewController, one called homeStepper the other called awayStepper. When I run the app on my phone the value for homeStepper changes just fine, however nothing happens when I try to use the awayStepper. I added log statements and they just show the value of the stepper never changing. It always sits at 0 no matter how many times I push either button on it. Here is my code: https://github.com/Zach443/ScoreKeeper/blob/c83d5eeaadafaad4f093437679d26a8b55ef5dd8/ScoreKeeper/ViewController.swift

You have a typo:
approxAwayScore = homeStepper.value
Should be
approxAwayScore = awayStepper.value

Related

Can you disconnect a command after it has been set with Mvvm-Light on Xamarin.iOS

I'm using Mvvm-Light to create a binding to a UIButton with the SetCommand extension. I can just call it in ViewDidLoad(...) but I want to connect it in ViewWillAppear(...) and disconnect it in ViewWillDisappear(...) like I do with the rest of my bindings. So all bindings are only active when the view is visible. If I do it this way currently then SetCommand is called every time I navigate back to the view and the RelayCommand is fired multiple times, once for every call to to SetCommand.
Is this possible? And if not, then why not?
Why do you want to disconnect a command?
If a UIViewController has disappeared, all of his controls can't be touched and seen. So the command will only fire when it appears again, I think this has already fitted your request.
If you do want to remove this command in the event ViewWillDisappear() you can use:
button.RemoveTarget(null, null, UIControlEvent.AllEvents);
This will remove all the events the button has. As you say when you SetCommand() again in the event ViewWillAppear() the RelayCommand will only be called once.

Swift IOS app won't start after idle for over 1 day

I have a simple app in Swift with just a few views:
A UIWebView
some TableViews
and another view with some data I download from my server
It all works well until when using the app I press the home button, leave there for a while then the iPad goes on sleep mode. A few days later I tap on the app icon and it won't start:
first tap on the icon will select the icon (goes a little darker) and deselect it a few seconds later
second tap will launch the LaunchScreen and crash a few seconds later
double tap the home button and quit the app will sometimes work
I'm just wondering if there is something I need to set on my code to handle idle/long periods of inactivity in something like viewWillDisappear or other methods?
If so I already have this in all my controllers:
override func viewWillDisappear(animated: Bool) {
timer.invalidate()
webView.removeFromSuperview()
}
Maybe I need to call super. in there too? or something else I'm missing?
You should definitely call super in your viewWillDisappear(animated:) method. See UIViewController Class Reference documentation. Also you might want to confirm why you are removing your webView from the view controller's hierarchy.
Discussion
This method is called in response to a view being removed
from a view hierarchy. This method is called before the view is
actually removed and before any animations are configured.
Subclasses can override this method and use it to commit editing
changes, resign the first responder status of the view, or perform
other relevant tasks. For example, you might use this method to revert
changes to the orientation or style of the status bar that were made
in the viewDidDisappear: method when the view was first presented. If
you override this method, you must call super at some point in your
implementation.
You probably have some null pointer exception and crash. Maybe you are calling some variable that is not set (and checked if not null).
Try disabling app funcionality (like downloading, storing and using data from server) and see where you app starts working normal again and then procede from there.
Sorry for vague answer but withouth code and maybe some log it is really hard to give specific answer.
And NO, you dont have to do anything special to handle idle/long periods of inactivity.

iOS Objective-C IBAction runs the code in method twice

I tried to run this method of code
- (IBAction)signInButton:(id)sender {
NSLog(#"Run Action %#", #"Here");
}
The result of this code log the "Run Action Here" twice in the console.
I initially loaded all my project import file (.m and .h) in one header file "Loader.h", I taught this was the cause, but I still experience the same issue even after I dissembled the header file.
Same Issue happens on other view controller.
What am I doing wrong ?
Thanks in advance.
It sounds like you've connected the action to your button or other UI element for two different events. For example, if you connect it to both the touch down and touch up events, a single tap of the button will trigger the action twice.
One thing you can do to diagnose the problem is to control-click on the view controller containing the action in your nib or storyboard and look at the Received Actions section near the bottom of the resulting popup. You'll likely see your action connected twice.
Another option is to set a breakpoint in the action and take a look at the sender parameter each time you hit the breakpoint. This will show you what object is triggering the action each time.
This seems to be some problem with the logging. It indeed logs twice from IBAction handlers. I put NSAlert, to make sure it's called twice, but it was called once, nevertheless the log was printed twice in the console.

UITableView not refreshing

I am creating a list and displaying it in a UITableView. While viewing I want to delete an item and then save the updated list, allowing me to refresh the old list with a refresh button. I use a button to save the current list, then a refresh button to reload the data into the view. The problem is the code within the save button always runs, even when I don't press the button. I can explain best like this:
btnSave.TouchUpInside += delegate { _ListCopy = new List<Tasks>();
};
btnReset.TouchUpInside += delegate {
tblTotal.ReloadData();
tblTotal.DataSource = new ListDataSource(_ListCopy,txtTotalCost);
};
tblTotal.DataSource = new ListDataSource (_ListOfTasks,txtTotalCost);
When I run this the table view shows the _ListOfTaskslist, when I press btnReset the _ListCopy is reloaded as the data source. The issue I am having is that the value for _ListCopy is assigned even when I don't press btnSave. In this case the view is cleared. If I comment out the line _listCopy = new List<Tasks>(); I receive a null reference exception in the table view Data Source here:
public override int RowsInSection (UITableView tableView, int section)
{ return _ListOfTasks.Count; } <-- exception
indicating to me that the value of _ListCopy is empty. I thought I could make _ListCopy = _ListOfTasks in place of new List. But, for some reason the code is running in the save button regardless, so I am never able to save the correct list value when I want it. Why is_ListCopy be assigned a value without telling it? I do not assign it a value anywhere else either. Can someone explain what is happening? Is there a different solution that I could use instead?
I discovered that I had my outlets setup wrong. For some reason I had two outlets wired to btnreset and no outlets for btnsave. So when I pressed reset, I was also firing off the code for btnsave. I solved the whole issue by correcting my outlets. As for making a copy of the original list: I was trying to simply make _ListCopy = _ListOfTasks for the save function. This only pointed to the memory location of _ListOfTasks, which included any changes. I corrected this by writing a foreach loop to copy one list to the other
foreach( var task in _ListOfTasks)
{
_ListCopy.Add(task);
}
Now I can press save and the first estimate is stored. I can do any deletions, and if the customer wants to revisit the initial estimate I can refresh the data.

UITableViewCell getting _accessibilityUpdateRemoveControl on deallocated instance

Edit: While my comments have an iOS 5 working example, I am still getting this for other versions. I've now implememted a test to only register and dequeue cells if iOS 5, but it's really puzzling!
still receiving _accessibilityUpdateRemoveControl exceptions, strange nuisance, appears to be something with the edit controls, nothing is retained so nothing needs deallocing, but will try, and post the answer if I find it!
This was working yesterday, and now it's not... I changed nothing!
Edit: Turns out, while reloadData causes the crash, the crash does not occur without my custom tableViewCell... hmmm, something about removing the + sign, but it doesn't happen with deletion!
Actual error is this:
[CustomTableViewCell _accessibilityUpdateRemoveControl]: message sent to deallocated instance.
What's funny is, the remove button works. Essentially it removes the item from an array, adds it to another, basically putting it "to another table". No crashing, works fine.
If I remove the line that reloads the data in the table, after the insert button adds it, it also works. Eg: Don't immediately reload the data, close window, come back, everything displays fine. The exact line, so far, that crashes it is in
[theTable reloadData], but that line, for the other table (as I update both) doesn't crash at all. Actually, thanks to that, I'm gonna view the headers for UITableView's functions, and view other answers with that specific line. I just didn't see this, anywhere, after searching for that weird function call.
I'm ensuring my cell is within memory, and even quit dequeuing just to ensure it's working. I'm stumped with this, hopefully will have solution in an hr or less.
Thanks
I stepped through Apple's code, line by line, read the name of every function and noticed this:
editControlWasClicked: (id) clicked
is called just before crashing. I combined that with the error message, and the fact I call [table2 reloadData] before this is called, and pieced those pieces together.
The cell is erased (so it moves to the other table), but somehow calls its system callBack "editControlWasClicked" after the table reloads... since it's on the main thread, I'm guessing the table stuff is multi-threaded... how else would it call these in order but do that After the reload??
So to test this, I used the "afterDelay" function, and low and behold, it worked.
You may be asking why I'm using an add edit control in one and subtract in the other... there is a purpose to that.
So, possible solutions: 1) use the afterDelay method of selectors.
2) Write a custom IBAction ('cause it's a xib) or otherwise use custom images and functions to ensure that doesn't get called back.
Note, 2 involves writing an extra delegate so that messages from the cell can reach the view controller.
Basic solution: use iOS 5, use the queuing, otherwise do one of the above solutions or figure out the threading/hooks and find a way to do this without delaying. (I would prefer such if I can find it)

Resources