I have an UIView with embedded an UITableView.
One text field in the same view should control the table's cells number.
If the user enters the number 4, immediately the TableView should change its cells number to reflect what the user entered.
The content of the cells will just be something like "Please select".
Then, when the user selects a cell, a Date Picker should come up, let the user choose the date/time and then, when the picker is dismissed, that cell should change to the date/time selected.
I'm going crazy with this since more than two days. I don't put any code here because I really have no idea where to start and all the things I've tried so far were a complete failure.
If anyone can lead me to the solution, I would really appreciate it.
Thanks.
If you're on the iPad, you could show a UIPopOverController from the selected cell when the user selects it. On an iPhone, you could present a modal view controller.
For this, see -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath.
You'll have to implement code that handles getting the value from the UIDatePicker when its presenting view controller is dismissed. Also, you'll have to host the UIDatePicker in a view controller, as there is no way (as far as I know) to present it on its own.
So, my proposed solution is:
Create a new view controller that hosts the UIDatePicker you want to present.
On that view controller, put "OK" and "Cancel" buttons.
Add a property to that view controller that references your "main" view controller. This is so that the view controller that hosts the UIDatePicker can send a message to the "main" view controller when you're done selecting the date.
In your "main" view controller, handle the tableView:didSelectRowAtIndexPath: event for your UITableView.
Present the view controller to show the UIDatePicker to the user.
If the user selects "OK", dismiss the modal/popOver view controller and update the cell with the new information (you'll probably need an array of NSDate values and a call to [tableView reloadData] to perform this).
If the user selects "Cancel", dismiss the modal/popOver view controller and DON'T UPDATE ANYTHING.
i think this tutorial will help you.. i have followed that too..i was also faced the same problem that you have..
Related
I have a MainController with a button
Click button will pushViewcontroller to UsersViewController
In UsersViewController, I will load an table view of users with an selected cell to be highlighted
Ask: How could I save the state of tableview or state of the ViewController after hitting the back button from navigationcontroller, And the next time when a initiate the UsersViewController again, the table view will be at last state.
while traversing from the page, save the details in a Manager object, and next time, whenever you appear on the page, check whether the details are there in Manager object, if true, show the details from the object itself, otherwise, show them like you do as now.
You can try to avoid using a pushViewController / Navigation Controller by using a TabBarController for example but that might change the behavior of your app.
Or avoid your UsersViewController being deallocated and just initialize it once.
In my test project I have a ViewController and a TableViewController controller embedded in a Navigation Controller. The ViewController is the main view, and the user can navigate to the TableViewController and then return back to the ViewController.
I am using a 'push' segue when going from ViewContoller>TableViewController, and the TableViewController is dismissed using [self dismissViewControllerAnimated:YES completion:nil]; when the user wishes to go back to ViewController.
In ViewController, I have a button that changes the text on a label:
-(IBAction)onButtonPress:(id)sender {
_myLabel.text = #"New Label Text";
}
When navigating to TableView, and then back to ViewController, the change in the _myLabel.text has been lost and the original text is restored. What is the best way to ensure UI data is retained when navigating between views? I might only have one label in this project, but at some point I will have many UI elements, for example, WebViews that need to keep a page loaded when the user navigates away and then comes back.
What would you suggest is the best method to implementing this?
Thanks for your time.
First of all, View is your data representation, any data is your Model. So you may store Model with its entities and values. Your controllers manage data to represent it on View or to change Model according to user actions in View.
So add some Model-object for storing _myLabel.text. And use this object for both controllers in your app.
Try to remove setting the text from the ViewWillAppear or ViewDidAppear method, put it in ViewDidLoad.
My problem here is not knowing how to utilize the edit button in a UIToolbar correctly.
Basically, I have 3 VC the first 2 are inherited from the Navigation VC and then I added a third.
The first VC displays an empty TableView until you add cells to it through the UIToolbar.
You then click on a cell it pushes to the second VC which displays information about that cell (think of it as a list of friends and the second VC displays the friends name and email). Now here comes my problem, I'm not sure how to properly use the edit button on the UIToolbar to edit the information on the second VC.
So I want to switch from the second VC to temporarily display another VC like you would in the iOS contacts app and then go back with the VC updated and displaying the info that was just entered on the Edit VC.
Im not asking for solution code just for guidance, I'm currently a student on break and trying to make something to keep me busy and occupied.
Thanks in advance to anyone who replies.
You should use delegate to update your VC. In your Edit VC, create a delegate with a function like "didFinishEditing". When you complete your editing, call that function. The implementation of that function must be write in your VC.
This topic may useful for you: How do I create delegates in Objective-C?
I have a One main view controller and in that I am having two sub view controllers named like rightViewcontroller and leftViewcontroller. When we press the menu items from the right view then I am changing the left view controller.That's working fine.Here my problem is If I get any alert that's only fixed to any of the View controller's.Then user able to press the other view which is not having the alert(those are custom alert's. I need custom alerts as per the client requirement)in iPad. Please Help me
Thank's in advance
When you get an alert on, say, the leftViewController, then disable the user interaction on the other viewControllers.
something like:
rightViewController.view.userInteractionEnabled = NO;
It seems when you present your alert you are showing it over one of the views like showInView:self.view when in fact you should show it over the parent view so it covers both like showInView:self.navigationController.parentViewController.view (that's just pseudo code).
Without seeing your code you use to present it currently I can't give you exact code.
Another way would be to first get a pointer to the parent view controller or navigation controller and show it there.
I have a simple iPhone app based on a navigation controller. There are two view controllers, VC1 and VC2, both with table views. VC2 also has a custom table cell. When a user selects a row in VC1, VC2 is pushed on to the stack. When the user selects the back button it's removed. Typical navigation stuff.
The problem I have is that the data in the cells in VC2 persists when the back button is pressed, so that when the user selects a different row in VC1, VC2 is pushed back on to the stack with the 'old' data in the cells, before the methods in VC2 reload the data.
I want to make sure that the data in the table in VC is removed every time the back button is pressed. I've tried releasing the tableview using viewWillDisappear, but it's not working. What's the recommended way of dealing with this situation? I've looked at the docs but it's not obvious (to me at least).
Try out this code snippet in viewWillDissapear or dealloc method.
if(yourTableViewCellObject) [yourTableViewCellObject release];
if(yourTableViewCellObject) yourTableViewCellObject=nil;
This might work.
I've used this technique several times since I asked the original question. As I mentioned in my comment to #Aditya, I've found that the easiest way to deal with this is to use viewWillDisappear to hide the tableview with the 'old' data, and when the user navigates back to the page, wait until the 'new' data is loaded into the table before making the tableview visible again.