I have following codition for my app as shown in image.
On left View : The different User selection will be done in table view.
And the selected users information will be needed on right view while pressing the button.
How can I do this ?
Use of Protocol is very simple to solve your problem.
When you tap on row on left side, then you just need to pass the object as userinfo and make a call to its delegate method which will be implemented in rightview.
This is very simple task if you know how to implement protocols for the viewController.
Hope this helps you.
Use a delegate pattern.
When a row is selected from the table view in the left view, call the delegate to notify the selection. Afterward your delegate (which suppose to be the right view's controller) can display the corresponding user info.
Related
This is maybe a simple question, but I don't have a clue the keyword i had to search for this...
I want to create a simple selector (I called it spinner in Android). This is what i want to achieve
Or it will take a whole screen if it's in ipod touch / iphone.
So, I have 3 button that represent filter (category, country, sort) for a ListView... and if I press one of the button, a popover / dialog should be appear to select the filter for each button.
thanks...
Please let me know if I need to add some information to make the question clear.
Its not so much typical that is it appearing.
Create a new UIViewController class with xib and adjust view size you want to display for combo box or popviewControoler. Then put navigation controller over and tableviewController.
And customize your UIViewController using its controller class. Controller class will be reponsible for displaying and selecting data.
Now in your MainViewController From where you want to show ComboBox or popviewcontroller.
declare popViewController instance variable,synthesize it.
implement a userdefined method here alloc your popviewcontroller class and assign it to popviewController instance variable of your class.
Then called it didSelectRowAtIndexPath.
When popover dismiss you set popViewController result in instance variable of this class so it can easily access in MainViewController class.
You can achieve combo box like functionality by adding a UItableView in a UIView and implement all the delegates of UITableView in that custom view.
Now you can add object of that custom UIView where ever you want that combo. Just you have to workout with some Frame setting.
My project has a few view controllers, let's say A and B.
In A I have a UITableView. When a row is selected, I pass the row number and cell text to view B, then pushViewController B.
In view B, when hitting the 'done' button I make changes to the underlying data (right now a Singleton array) and then pop back to view A. In view A viewDidAppear, I reload the UITableView to see the new data.
Is this the best way to do it?
Or should I be reloading the UITableView when the 'done' button is hit?
If so, how do I reload a Table in view A from within view B?
Thanks.
It is better to reload the data directly when you hit the "Done" button. You can do that by a Notification Center. Please check this link for more details about Notification Center.
ViewController "A" should certainly be responsible for deciding to reload the table data. I would consider putting that into the "viewWillAppear" method of ViewController A. That way the table is reloaded before being displayed to prevent and "flickering".
There is nothing very wrong about this, except that your table will be reloaded every time it's viewDidAppear is called, which may not be very good depending upon the size of the table. The best way would be to use #protocol and make a quick delegate design pattern, though this might seem unnecessary headache if you are not used to it. You can also use NSNotifications, although I would not insist using it in this case, as there are not many observers listening to the event.
Instead of using NSNotification. You can assign view A to be view B's delegate which is a much cleaner design pattern.
So in view A it would look like
ViewB *b = [[ViewB alloc] init];
b.delegate = self;
and the in viewB when you are done making modification u call
[delegate updateTable];
where in updateTable is a #required method in the delegate declaration and since its required viewA will need to implement it if it says it conforms to that delegation.
Also this method will be called before you pop the viewB out.
I'm working on my first app and I've issues on how to layout some of its logics.
Basically, what the app is supposed to do is to show a first screen when launched where user can fill in some values and press a button that opens a tableview which shows results. The first screen (view), outlets and connections are all working fine. The issue I'm having is how to leave this "home" search view and show the results to the end user on a table view. Right now, I've only 1 view with its related View Controler and this controller handles the tasks of taking user inputs and get results throughout a HTTP post request.
I need your guidance...Thx in advance
Stephane
Is there a reason that this all has to happen on one screen? iOS is set up to allow for this to happen very easily and (I think) attractively by using a UINavigationController and pushing in a new view controller (could be a UITableViewController or simply a UIViewController that contains a UITableView).
If you MUST have all of this take place in one view, Swastik is correct that it will require some view acrobatics. One way to do it attractively is to use the UIView animations introduced with iOS 4.
Here's Apple's UIView documentation: UIView Class Reference
Specifically, check out the CLASS methods of:
1. animateWithDuration:animations: (with or without completion:)
2. transitionWithView:duration:options:animations:completion:
Note that these methods will require you to learn a little bit about blocks, but it's worth it and I think blocks give tremendous power!
With the methods mentioned above, you could fade out your form and fade in your tableview, or maybe just move the form off-screen while the table view flies in. The possibilities are limited only by your imagination.
u can add a table in ur xib.Initially make it hidden, & when u need to show it unhide it & also if u want to update table's data , you can reload the data of the table.
I want to implement a drop-down list in an iPhone application, the same like you might have seen in iBooks when you select PDFs/Books.
I have a slight idea how to implement it, just correct me if I am wrong:
Create the button
On a click event of the button define a CGRect and within the CGRect draw a LoadTableView
Load TableViewData at runtime.
Is that correct? If not, how should I do it?
Here's a much better/easier way to do it.
Create custom UITableViewController and associated nib. Use this class to encapsulate your tableView and data.
When the user clicks on your button, instantiate your custom view controller and display it modally using presentModalViewController:animated
When the user has selected an option from your popup view, call back to the parent view with the results.
Dismiss your table view with dismissModalViewControllerAnimated:
This is what iBooks does with a highly customized UITableViewController.
Are you looking for a UIPickerView?
This component gives you the possibility of selecting from a custom number of elements through a dedicate table view. Use it in conjunction with a UIActionSheet to get the best results.
I'll be using a datePicker several places in my app. I don't want to "clutter" up each and every viewController with the delegation methods for the UIPickerViewDelegate and UIPickerDatasource, plus I would be doing the same delegation methods over and over again.
Every time the datePicker is in play it's sole purpose is to slide halfway up the screen, let the user select a date and then disappear again.
I was contemplating a wrapper viewController (DatePickerViewController) that implemented the datePicker delegate methods, then did a NSNotification with the value which the user selected, which again was caught by the viewController instantiating the DatePickerViewController.
This would make me a decoupled datePicker and let the viewController instantiating the datePicker know nothing of a DatePickerDelegate, but just know that there would potentially come a notification containing an NSDate. Seems rational to me, like something I would do in other languages. But please correct me if Im digging myself a hole here:)
As I started breaking this down I ran into some difficulties, Im not very experienced in Objective C and Cocoa.
I can build a viewController that in it's viewDidLoad presents a datePicker, running just this will result in a blank white screen with a datePicker in the bottom half of the screen. If I use "presentModalViewController" from the viewController that instantiates the (custom) DatePickerViewController, it of course slides up and covers the whole screen. I would like for the user to still have half the view visible. Much like setting the time in an event in the iCal app. (except they push a new viewController onto the stack). Ahh just realized that what I mean is exactly like the keyboard when it slides in and covers half the screen.
So I guess my main problem is: can you build a viewController that behaves like the keyboard when added to a view. But do all this in the ViewController that is added instead of in the controller instantiating the view.
Hope it makes sense:)
Thank you
(1) Put the picker in a model (edit: should be modal) view. This is how the keyboard is implemented.
(2) The picker controller/delegate should only control the model view and the picker.
(3) In the delegate create two properties such as:
id *target;
Selector theSelector;
and a method like:
-(void) sendPickerResultsTo:(id) theTarget forSelector:(SEl) theSelector;
(4) Before displaying the picker model view, set the target to the calling controller and the theSelector to a method in the calling controller. You can configure the selector method to pass an arbitrary amount of data. It would look something like:
-(void) pickerResults:(NSArray *) pickerResults; //could pass any value as long as it's an object
[Note: this is kind of thing you define a protocol for if you use it a lot]
(5) When you have the picker value just have the picker delegate call:
[self.target performSelector:theSelector withObject:anArrayOfPickerResults];
(5) Add the appropriate method to any controller that needs to evoke the model picker view and set the controller as the target before you display the model picker view.
This will give you a self-contained model picker view that you can attach to any view and which can send its results to any arbitrary object that implements a method with the right signature i.e. implements the protocol.
This is basically a do it yourself version of UIControls addTarget:action:forControlEvents: