is it possible to declare an NSArray withobjects of view controllers?
I'm trying to use two buttons to call an array that will loop through and count through 20 different views.
Right now, my array works in calling and displaying multiple images in a single view application.
what would i do to create an nsarray of view controllers, so that every time the "next" action method is called, a new view is loaded, and essentially, counted through the array?
This is currently what I have listed in my array
-(IBAction)getNextView {
imageArray=[[NSArray arrayWithObjects:
[firstViewController.view],
[secondViewController.view],
[thirdViewController.view];
}
But I think i am missing a valid point of updating the mainview with the elements in the array...
Thanks!
UPDATE :
This is what I am trying to achieve...
yes why not, you can create an NSArray with objects of viewControllers
Related
I have been searching how to send data between multiple view controllers but its only seem to be possible to send from one at a time?
I have five view controllers and I want to add text in to the TextFields I have in four of the five of them.
When I am in the last view I want to get the data from the four previous controllers.
You should use the NSUserDefault class.
With the NSUserDefaults class, you can save settings and properties related to application or user data. With NSUserDefaults you can save objects from the following class types:
NSData
NSString
NSNumber
NSDate
NSArray
NSDictionary.
I am 100% sure this link could solve your problem..
http://code.tutsplus.com/tutorials/ios-sdk-working-with-nsuserdefaults--mobile-6039
I have an array of users
var selectedUsers = [User]()
users are added to this array as they are selected in a UITableView (see screenshot: https://www.dropbox.com/s/uk03mhgi3x4jesy/File%2006-10-2015%2C%2018%2003%2044.png?dl=0)
What I'm having difficulty with is when I press back and then reload the view controller, all the checkmarks disappear.
Is there anyway I can keep track of the selected cells?
Thanks in advance
You could use a delegate to pass a array between the two viewcontrollers. For example, each time you select a row, you can store the userId's associated with the row, in the array. So if you were to press back and then open the view with the UITableView, before you load the UITableView, you can first check if there is an array being passed to the viewcontroller containing the UITableView / if there is an array, check if the count is greater than 0. If the array is not empty, then use a for loop to cycle through the array of users being displayed with the array being passed containing all of the previously selected id's, then add the check marks that match up to the Id's in the array.
Here is a tutorial that possesses a similar example: http://makeapppie.com/2014/08/04/the-swift-swift-tutorial-why-do-we-need-delegates/
The answer to this question is kinda dependent on what you want the application to do... Do you want the User selections to persist even if the app is closed? If so consider using NSUserDefaults or CoreData. Otherwise store the data somewhere that does not get blown away (maybe the root view controller of your application). You could for instance implement the delegate pattern on the view controller with the table view and pass the values to the container view controller.. Just some ideas.
So you can use class NSUserDefaults to save small amount of data. If you want to have persistent store so you have to use Core Data that helps you store you data with scheme you provide.
If you just want to pass data from one view controller to another view controller so you just need use delegation pattern or you can use method prepareForSegue where you can pass some data as well but you can't store this way, just pass.
If you make your question more detailed you will get more explicit answer.
Hi I am new to Core data. I am having difficulties in reloading my child objects or the NSSet objects which is located on a second tableview.
So I have two tableview controllers, the first one is Budget where I can add or delete a budget. Within that budget object it has a one to many relationship with Expense object (So the Expense is the NSSet).
After when I tap into one of the budget cells, it takes me to the NSSet of Expenses, I then converted the Expenses NSSet into NSArray by using the allObjects method like below:
_expenses = [[_currentBudget expenses]allObjects];
I then populated the table view controller and it shows me all of the individual expense available within that budget. I then have an add (+) bar button to add an expense into the current budget (or call the predefined method that core data gave me: -(void)addExpensesObject(NSManagedObject*)object
Everything is great and it can be saved. However.... once I saved I am not sure how to reload the NSArray of expenses as it is not like the fetchedResultsController. (I am able to reload data on the first tablview once a budget was added because i used the NSFetchedResultsControllerDelegate and implemented the changes/update/insert etc methods).
So my question is, how do I reload those set of NSArray objects? I tried to add in viewdidappear [[self tableview]reloadData] but that didn't work for some reason.. But when I tap back to the first tableview (budgets) and tap back into the expense... it reloads.
Many thanks!
The simplest solution would probably be to use a fetched results controller in the
second table view controller as well. Instead of passing
[[_currentBudget expenses]allObjects]
to the second view controller, just pass _currentBudget. In the second view
controller, create a fetched results controller with a
fetch request on the "Expense" entity and using a predicate like
[NSPredicate predicateWithFormat:#"budget = %#", self.currentBudget]
I loaded my pList into a table view controller that segues to a view controller. I can't figure out how to load the data corresponding to the cell tapped into a label on this view controller. The plist is an NSDictionary, by the way.
In viewDidLoad of the table view controller I have:
NSString *myFile = [[NSBundle mainBundle]
pathForResource:#"recipes" ofType:#"plist"];
recipes = [[NSDictionary alloc] initWithContentsOfFile:myFile];
courseKeys = [recipes allKeys];
I am not sure how to tell the label that the name of the recipe chosen was X so you display the ingredients for X.
Thanks for the help!
Kevin
Don't forget - a UITableView is a way to display your data. Once a user selects a row within a UITableView, you get notified of this via your UITableViewDelegate method (specifically didSelectRowAtIndexPath). You can use the indexPath to grab whatever data you need from whatever data structure you're working with (in your case, NSDictionary) and pass it on to whatever controller you are displaying next by implementing the prepareForSegueue method correctly. I would suggest defining a property in that next UIViewController and assigning it the data to be passed on in prepareForSegueue. I would however pay some thought as to wether you wish to pass a direct reference to the data or maybe a deep copy of it - it really depends on what you're trying to accomplish in that VC.
I don't know how I can share the same data between two tab bar items.
One tab uses nsfetchedresultscontroller and the other table is just a normal view that should use the same data as my fetchedresultscontroller.
If i had two normals views, I would just make my object a singleton, and let the tableview and normal view use the same data.
But now i have a fetchresultscontroller and a normal view. I was thinking about just using another fetchedresultscontroller for my normal view, so I have all the features such as fetch cache, notifications and such..
I know fetchresultscontroller should be used for tableview, but I guess I can use it for non tableviews as well.
Somebody knows what it is I should do? I couldn't find documentation from apple on this matter.
Your data should have noting to do with your viewControllers or views - that is, if you follow the MVC style. If your data is only available in one viewController and you don't want to extract it out into its own class, then provide methods in your viewController that can be called by the other viewController to get the data.
For example, have methods like this:
- (NSString) getNameOfSelectedUserAtIndex:(int) index;
- (int) getCountOfSelectedUsers;
- (NSSArray) getResults;
And then from within your other viewController, call:
string = [fetchedresultscontroller getNameOfSelectedUserAtIndex:i];
count = [fetchedresultscontroller getCountOfSelectedUsers];
array = [fetchedresultscontroller getResults];
You have to make sure you add fetchedresultscontroller as an instance variable to your other
viewController and set it probably in its viewDidLoad.