How to write to a sidebar menu from another view - ios

I have an app where there is a sidebar menu. Like the Instagram and Facebook apps, I have a user settings view, where I can upload a picture. This picture is also shown in the sidebar menu. This picture is loaded once, when the sidebar menu tickers viewdidload.
The problem is if the user changes the image in the user settings view, I can't get it to update the sidebar menu. The viewdidload runs only once.
The best thing would be if i could set the UIimage in the sidebar from the user settings view - but is this even possible?
I not that good at Xcode (swift) yet so bear with me.

Without code samples or knowing the implementation of your sidebar these are just guesses. viewDidLoad is only called once when the view is added to the hierarchy. Try moving logic that needs to execute on each subsequent appearance to viewWillAppear.
In the past when I've implemented a sidebar, I've used a UITableView or UICollectionView. This simplified determining what was selected and reloading the state/data of the view as you're using well defined delegates and methods. This worked well for me but YMMV.
The best thing would be if i could set the UIimage in the sidebar from the user settings view - but is this even possible?
It is probably best to keep your sidebar and settings view separate. They don't need to know that the other exists. This doesn't mean they shouldn't share the same data or an abstraction (service class, plist, etc) over that data.

You have several possibilites to get this done. A non exhausting list:
NSNotificationCenter
Key Value Observing
Delegation
Make your menuVC a delegate for the viewController where your profile-image-change action can be performed. When someone changes the profile-image, call:
delegate.profileImageDidChange()
In your delegate protocol, you have to define that method of course. Please see the tutorial on Delegation (Hyperlink). If you need more help with implementing it into your code, just ask another question or edit your question.

Related

Xcode recreate UIViewController possible?

Is there a way to "recreate" a UIViewController from within itself. Android SDK 11 added recreate() method to activities. In researching the topic I found this for UI Restoration: UI Restoration
I don't think this is really what I'm looking for.
Basically, my app is a flashcard app which allows the user to retry missed words if they missed any when they finish the deck. In Android it's a simple this.recreate() with missed words stored in SharedPreferences and then reloading the view with the new SharedPreferences field. I have the UserDefaults side of this working. I'm not following if recreating view is possible for iOS. Maybe by segueing out and then back in?
I found this Q&A: stackoverflow link
But I'm not using Navigation Controllers. Just a simple UIViewController.
Thanks for reading!
I presume you want both the view controller's properties and its views to be as before. There's no "magic bullet" for doing that; you just have to do it, yourself.
Now, if your view controller is correctly constructed, its properties automatically dictate its interface. The usual thing, therefore, is just to save off the property values (e.g. in UserDefaults) and later restore them and the interface from that.
It is also possible just to retain the view controller so that you can use it again later, directly. It is, after all, just an ordinary object. This can be a little risky, as the view controller's view is memory-intensive, but there are ways to reduce the amount of memory it occupies.

UIScrollView multiple page confusion

So I have an existing app I'm working on for a friend...
and let's say I double click on animals_real and I get this screen...
Basically all I want to do is create a back button back to the home page on the animals_real page and all the other ones like it(body_parts_real, cleaning_real, etc.) but for whatever reason I can't find the xib file or the code for it and I'm not entirely sure what file it would be in. Also, since I am fairly new I'm not entirely sure how to implement the back button. Any help is greatly appreciated.
----------------------------------EDIT 1------------------------------------------
The main page works under ViewControllerForIphone.xib and the settings page is under SettingViewControllerIphone.xib. This led me to believe that the other pages would be under the SubPECSViewController_iPhone.xib. However, if I go in and edit that it doesn't change anything when I run the simulator. So, basically I have been trying to understand UIScrollView better and how it works but I am kind of just stuck.
Welcome to iOS. Other commenters will point out that you should start here at the UICollectionViewDelegate Reference (which you can also get to through Xcode (shift+command+0)
Basically, a uicollection view populates itself based on some array of data.Look here to see what's going on
(void)insertItemsAtIndexPaths:(NSArray *)indexPaths
When you tap on animals, this method is called:
– collectionView:didSelectItemAtIndexPath:
Some logic happens here, and I'm presuming you load the collectionview from yet another array.
To solve your original problem of a "back button," you might simply want to reload the viewcontroller's original datasource or possibly "pop" back up the navigation stack. Again, without seeing at least part of the code, there's very little we can do except speculate :)

UITableViewController with SearchBar

I have tried both ways below to place SearchBar on UITableView.
TabBarController > UITableViewController(Put SearchBar)
TabBarController > UIViewController > UITableViewController(Put SearchBar)
When I try the second way, then it doesn't work.
(SearchBar cannot show on UITableViewController)
Can anyone tell me what happend?
Here is my xcode project file:
http://www2.zshares.net/tg14vowqzvaw
the usual way to do this would be to put the saerch bar in the header-section of the uitableview its supposed to search. you can do this using the
-tableview: viewForHeaderInSection:
method from the UITableViewDelegate-Protocol. his works in both TableViewControllers and regular ViewControllers that just have a TableView on them. see the mail app on the iphone for an example of this.
if you really NEED the search bar to be outside of the tableview, then you will have to use a regular view controller and just place the search bar in a view above/under the tableView.
other than that, i dont know what to tell you. And what is a TabbedViewController? Do you mean TabBarController? What does that have to do with search bars? Im kinda lacking the time to go through your project, so if you rephrase the question, maybe i can give a better answer?
EDIT-----------------------------------------------------
tableviewcontrollers will do that to you. basically, they will allow ONE tableview to be inside them at a time. also, this tableview WILL ALWAYS fill out the entire space available. Now, there is an exception to this that you cam make use of: Elements like a NavigationBar or a TabBar are allowed alongside the tableview, since they are required for navigation. So if you can put your stuff in one of these, its entirely fine. This my seem counterintuitive, since when do i want just a naked tableview on my screen? the answer is: more often than not. Tableviews are HIGHLY customizable using the UITAbleVIewDelegate-Protocol specified here:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intf/UITableViewDelegate
Do yourself a favor and read that doc, i almost guarantee that you will save time in the long run.
For Example: You know the contacts app on your iphone? If you go into the details of one specific contact, you will find a pertty sophisiticated presentation of the data, that will even go into editing mode if you tap edit. It has a header, multiple segments, and a footer.
Surprise: ALL OF THAT is just a single tableview in a tableviewcontroller, customized via the protocol. Let me repeat: you are wasting your own time if you try to do it any other way. tableviewcontrollers exist for a reason. usem them

iOS: UI Ideas for moving items between multi-level tableViews

I am building an iOS app that allows the user to browse a tableView, click a cell, then navigate deeper into another tableView using a navigationController.
I have a requirement to be able to move any of those items/cells to another place in the navigation stack. Right now my idea is, once the user selects the cells to move, to display a modal tableView that will allow the user to navigate through the same structure as before, but this time choose the location (by pressing and holding) to place those cells.
Are there any other UI ideas or clever programatic ideas that anyone might have that could be a better solution to this problem?
Perhaps take a look at how Apple's iOS Mail moves email messages between different mailboxes?
This also basically displays a modal view controller, but it flattens the hierarchy, by indenting nested items below their parent objects. You than just select the item that is the destination.
This of course only works if your hierarchy is not too deep, otherwise it's probably best to do it like you outlined it. The only thing I would perhaps recommend doing in addition, is to also have some sort of visual method (button?) to select the destination. A long press by itself might not be intuitive enough.

Hiding the Root View of a UISplitViewController

For the app that i am developing i have used a UISplitViewController as my base, but have modified, or attempting to modify the split view controller like that of Alice Bevan–McGregor's on http://vimeo.com/13054813. However in my app i have a table view with a list of options, and every time i click on an option it loads the corresponding detail page from a detached nib file. So, at the start of my app i can see and use the hidesidebar fine though it displays a white page. when i choose an option, the toolbar is overridden by the corresponding nib, so it dissapears. What i am not sure about is how to connect it in a way that it appears on every page(nib) everytime i choose an option from the tableview. I have been stuck with this problem for quite a while now.
essentially i would like the toolbar to maintain its functionality no matter what page i am on.
Anyone have any ideas?
May be you should give a try to this http://mattgemmell.com/2010/07/31/mgsplitviewcontroller-for-ipad
It has the following method
- (IBAction)toggleMasterView:(id)sender;
My own implementation of custom splitview using navigation based app # https://github.com/palaniraja/cUISplitViewController
Also try Salva's implementation http://iphone-dev-tips.alterplay.com/2011/05/custom-uisplitviewcontroller-for-ipad.html

Resources