in my app i send a GET
to my server and receive some response. I have TavleView and TableViewController classes expect from my main view controller class. I do the parsing in my main ViewController and i want to populate the TableViewCells with the results i receive from the first ViewController. And also i want to display the details of any cell in a new ViewController
called DetailViewController
. Now any navigation amongst the Views work as how i want..
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- how do you prevent page scroll in textarea on mobi
- Custom UITableview cell accessibility not working
相关文章
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- Unable to process app at this time due to a genera
- Popover segue to static cell UITableView causes co
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
- TransitionFromView removes previous view
- Open iOS 11 Files app via URL Scheme or some other
Well @ilhan çetin based on your request in the comment above here is a deeper explanation of the solution I propose.
First, in case you don't know what is a Shard Data Model, a Shared Data Model is a class that we define in our project and we create a
static
instance of it. Since that instance isstatic
this means it exists for all our classes all the time. We use this static instance to share information between different classes in our project like what you need here in your question. For example if you feel that you need to send a string value from a class to a class you can put in the Shared Instance anNSString
member. Here is how we do the Shared Instance:The .h file (assuming that my class is named
MyDataModel
):In the .m file:
From now on in our program, in any class that we need to access this shared string we will
#import "MyDataModel.h"
and access the string by:[MyDataModel sharedInstance].stringToBeShared
. Now that we have a sharing mechanism ready we will move on to see how to populate the table in the other view.In your code there is a comment that read:
You are asking for 2 things in this line but only one can be done in this part of the code. We will now populate the table and in the view of the table when you click on a row we will push the details you want.
To be able to populate the table we will need a function that will do so in the same class where the table exists. Let us name it
populateTable
. Well how will we be able to call this function when we are in a different class, and who will we send it themessID
value? To send themessID
we will use the Shared Instance, so you will add what is needed to hold themessID
value. Now to callpopulateTable
we will use Notification Center (described in the previous answer I posted).A Notification center is a mechanism used to call functions in different classes. So in the class that contains
populateTable
you will add a listener to it in theviewDidLoad
as follows:We will use the string
@"DoPopulateTable"
to call this listener. Now inside your loop you will do 2 things:messID
in your Shared InstancepopulateTable
using:[[NSNotificationCenter defaultCenter] postNotificationName:@"DoPopulateTable" object:nil userInfo:nil];
By this you have populated your table as you asked. Are we missing something? Yes the complete data that you will push later on. If the data is important and will be needed after you turn the device off then you have to store it in a sqlite3 database. If not (I will demonstrate the not!) you can store the information inside a
NSMutableDictionary
where the keys of this dictionary are themessID
(to be able to retrieve them when you click on the table), and the values of the table areNSArray
s where each array conatins all the info you need.Now when you want to push the information in the view that has the table, you can call each element inside the array using
[yourArrayName objectAtIndex:theIndexYouWant]
.I hope this helps you, and remember, no headaches at all ;)
go check out WWDC 2011's podcasts, WWDC 2011 - Session 309 - Introducing Interface Builder Storyboarding.
i believe this is the correct video and it will demostrate you exactly what you are looking for. they revamped UITableView's and added a lot of functionality into the IB storyboard in ios5. it will help demonstrate how you can take data in one View Controller and and display it in a second UIViewtable Controller.
I will read the code that provided in your comment above, but in the meanwhile I think this link can help you a lot. It is a way to send information between views, so you can parse your data in one view and send them to another one easily using this technique.