Fire UIActionSheet in ViewDidLoad first load only - uiactionsheet

I have a UIActionSheet (sheet A for short) with a switch statement of which one case: fires a 2nd view. Then in the 2nd Views Viewdidload method I fire a 2nd UIActionSheet (sheet B for short). Sheet B uses a switch statement to set the text in 4 places 2xlabels & 2xtextViews.
Now because I have sheet B fired in the viewdidload method each time i select one of sheet B case's from its switch statement it reloads the view to populate the labels and textviews but relaunches the UIActionSheet again, obviously as it is in the viewdidload.
Any suggestions on how to fire sheet b on first load only?
im thinking to use an if statement.
example
if (textView.text=#""){
//fire Action Sheet
}
any better suggestions or ideas, i read about creating a file in the viewdidload and then if file exists it would not call action sheet and if file did not exist it would?

I ened up changing my methods to fire from an IBAction instead of the viewDidLoad method

Related

Custom UITableViewCell with UITextField : textFieldDidEndEditing is too slow

I have a custom UITabelViewCell class that also implements UITextFieldDelegate
I also implement textFieldDidEndEditing so that once a field is done being edited I get a call back so that I can store the value that was typed in back in to the data array that loads the table
Seems like I have to do this or the data array never gets the type in values.
I edit various rows and when I click to the next row i get the textFieldDidEndEditing for the previous cell as expected. So far so good.
Now the problem. In the last cell I edit the cursor is still in the UITextField. I click a button to 'evaluate' the list of items in the table. Clicking the button to 'evaluate' the table causes its routine to kick off immediately. HOWEVER, the 'evaluate' finishes BEFORE get the final textFieldDidEndEditing for the field where my cursor was sitting.
That is, i do get the textFieldDidEndEditing for the field where my cursor was sitting but I don't see that call back until too late. i have already 'evaluated; the array and then afterwards I stuff the last typed value in to the data array that load the table.
How do I get the 'evaluate' to wait on the last textFieldDidEndEditing (IF there is one to come)? OR what do people typically do? Put in some kind of pause for my 'evaluate' so that there is time for the textFieldDidEndEditing callback to happen first?
I have a separate question on a second but related problem here Know the row number inside custom UITableViewCell - new wrinkle

textFieldDidEndEditing not called in a tableview inside a navigation controller

I have a tableview controller inside a navigation controller. This table simply shows one textfield in each row. In my navigation controller I have a “Done” navigation item that gets all the values entered in the textfields and shows the next screen.
The tableview controller implements UITextFieldDelegte and textFieldDidEndEditing to store the values of every textfield in its datasource (array of strings). In cellForRowAtIndexPath I also assign the delegate of the text fields to themselves. This all works well if I tap on the different textfields, I see how the datasource is properly updated.
My problem is when I do this sequence: type a value in one text field and then tap on the “Done” navigation item. I see that textFieldDidEndEditing is not called so the value is not stored. I also tried with textFieldShouldReturn and textFieldShouldReturn but nothing.
I have read many similar posts and I think the problem is that the "event" is being caught by prepareForSegue instead of textFieldDidEndEditing. If this is correct, I don’t know how to deal with this since I don’t know how to identify the indexPath of that “last edited textfield” when the Done is tapped.
Another related question: I have seen two approaches to get the indexPath of the cell containing the textfield when textFieldDidEndEditing is called:
1) textField.convertPoint + tableView.indexPathForRowAtPoint
2) tableView.indexPathForCell + textField.superview
Both seem to work well without differences (except for the issue that I just stated). Is any approach better than another?
Many thanks in advance for your help!!!
PS: if possible, in Swift code, please!
On click of done button you can add this line,
[self.view endEditing:YES];
This line will resign your currently active text field, and will call your text field delegates.
If you are displaying all text fields within same table section in that case you can assign indexPath.row to textField.tag, and using that tag you can create indexPath.
This is how you can address this:
Step 1 : Keep track of your active text field. You can keep a strong reference to it and set it whenever a textField is activated. Something like this:
self.inputField = iCell.inputField;
Step 2 : Once your Done button is tapped, add below line in action handler.
[self.inputField endEditing:YES];
PS: Alternatively, you can simply call [self.view endEditing:YES]; without the need to track the current active text field. I, personally, go with keeping reference to textfield as it helps me doing other stuff around current active textfield.

iOS/Swift: in which function between viewDidLoad and viewWillAppear am I supposed to query a database?

In my app, being developed by Swift and XCode 6, I have to query a database and according to that answer then I'll modify and show some UI widgets which, in my case, are three colored buttons whose I have to change their text which consists in a number.
These buttons indicate the number of tasks assigned to an user and they have different colors according to the tasks' priority.
So, shall I query the database in viewDidLoad() function and then change the buttons' text in viewWillAppear according to the answer? Is that right?
Yes you can query in viewDidLoad and do UI modifications in viewDidAppear.
Actually it depends on your need.
If your result will change every time OR if you wanna refresh data every time your View's display then query and modify UI in viewWillAppear OR viewDidAppear as viewDidLoad will query only once at the time your View first loads.
You can query a database whenever you want.
ViewDidLoad will only get called once per instance of your view controller. It is typically used for initializing objects.
In view[Will/Did]Appear you typically update your UI to reflect the newest data you have by setting label text and image view images.
Your described approach is correct if you don't need to re-query the database every time a view appears.
yes you can query it in viewDidLoad but if you do it in viewWillAppear will be more good because viewDidLoad calls once when view loading first time and never called again until unless view will deloc but viewWillAppear call every time for example you have one view and it have navigation view inside and you navigate inside the other view so when you press back button viewDidLoad will not call but yes viewWillAppear will always call.

Selection disappears in EKCalendarChooser

I show EKCalendarChooser in popover. When user selects a calendar in the chooser I get its calendarIdentifier. Everything goes smooth till this point but When you reopen the popover the selection in the chooser disappears. How to maintain the selection or how to reselect the calendar again when user open the chooser popover again.
If EKCalendarChooser is normal UITableView I can easily match my db value with that of the displayed cell and make it selected. But here how do I set EKCalendarChooser tablecell selected? I do have the calendarIdentifier...any Ideas?
plz help me out.
Thanks in advance.
As the user works with the EKCalendarChooser, use the calendarChooserSelectionDidChange: delegate method to keep track as the user changes the selection. You can store the selectedCalendars property value each time this method is called.
Then, the next time the EKCalendarChooser appears, set its selectedCalendars property to the selection you previously saved.
Try to build a data layer to your application with reference to MVC design pattern see here.
Save the popover selection state (and the other data) at the data layer (model).
After that, access this data layer (model) each time u open the popover and configure the popover according the data.
Anyway, to to make cells selected or deselected in UITableViewDelegate methods:
tableView:didSelectRowAtIndexPath:
tableView:didDeselectRowAtIndexPath:

UITableView reloadData fires only once

I have a TabBarController with two tabs SCHEDULE and DATE RANGE
When the view loads I'm hitting a webservice to collect the end users Schedule for that day. After parsing the XML I call ScheduleTable reloadData and all is well. I have tons of NSLog statements to follow the performance.
Clicking the DATE RANGE tab displays a DatePicker. After selecting the date range I have a button which when clicked passes the dates to the webservice again. In my log I can see the new dataset and can verify I have the data I need, when the code reaches the reloadData line, it does not fire the UITableView reload methods.
Any help is appreciated. I've tried viewWillAppear and self.ScheduleTable reloadData, neither have helped.
Check to see if you've connected the UITableView to the ScheduleTable IBOutlet in Interface Builder.
You say that the first refresh is working. That may be because it is automatically done by the tableview.
I understand that the second time you are calling reloadData programatically. If you haven't connected the IBOutlet, then your ScheduleTable variable is nil and [ScheduleTable reloadData] will do nothing.
when the code reaches the reloadData line, it does not fire the UITableView reload methods. Any help is appreciated. I've tried viewWillAppear and self.ScheduleTable reloadData
Just before saying [self.scheduleTable reloadData] (never start an ordinary variable name with a capital letter), log the table:
NSLog(#"%#", self.scheduleTable);
I'm betting it won't be the table and that you're accidentally sending this message into empty air.

Resources