Best scroll view in Xcode 5 - iphone

I'm using a scroll view for half of the screen with the following code which I got from a tutorial:
In .h #property (weak, nonatomic) IBOutlet UIScrollView *scroller;
In .m #synthesize scroller; and in viewdidload [scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(320, 1000)];
I haven't made any other changes. The scroll view works BUT it is very difficult to edit its content in Xcode because I cannot see the full view of the scroll view in storyboard, so how am I supposed to add/edit objects? Or is there a better tutorial out there which I should follow? There was another one which suggested changing the size of the ViewController to Freeform but I couldn't get that one to work.
Thanks

Related

designing a scrollview in stroyboard with xcode4.5

I have created a app project with story board in Xcode4.5
I've created a table view, and embed with Navigation controller. After tap the table view cell, I've create a segue to a detailed view.
I need to put lots of information in this detailed view, so I decided to make a scroll view.
I've create a view controller and add a scroll view in the view, set the scroll view height larger than the view height, and I arrange the labels and image views in the scroll view.
BUT after I build and run the app, my scroll view can not scroll at all.
I'm not sure where was the problem. Can any one kindly pointed out?
Thank you very much.
EDIT
my ItemViewController.h
#import
#interface COSViewController : UIViewController
...
#property (nonatomic, retain) IBOutlet UIScrollView *itemDetailScrollView;
#end
connect the itemDetailScrollView with Scrollview in connect inspector.
my ItemViewController.m
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.itemDetailScrollView.contentSize = CGSizeMake(320, 600);
}
Scrolling of scroll view depends on the content size.
Your content size needs to be greater than the size of the scrollview frame.
scrollView.contentSize = <Your actual content size>

View behind ScrollView or not? And how to do so with storyboard

I use a UIScrollView for some of my views to display some long textviews. I'm using XCode 4 and in the Storyboard I have placed the UIScrollView directly onto the ViewController scene.
Now I see in tutorials and stuff that people have a regular View between the view controller and scrollview. Is there a reason for doing that?
I've tried doing the same in my app following this tutorial, but I can't make it work with the storyboard, can't find the connection etc..
It looks like it works fine doing it my way in the simulator, but should I find a way to put a view behind it for some reason? If so, how can I do that properly with the storyboard?
Here's code for how I've done it, + made the connection from the Outlet to the ScrollView in the Storyboard.
InfoViewController.h
#import <UIKit/UIKit.h>
#interface InfoViewController : UIViewController{
IBOutlet UIScrollView *theScroller;
}
#end
InfoViewController.m
#import "InfoViewController.h"
#interface InfoViewController ()
#end
#implementation InfoViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[theScroller setScrollEnabled:YES];
[theScroller setContentSize:CGSizeMake(320,750)];
self.navigationItem.title = #"Title";
}
#end
PS. I can't find a way to scroll down through the scrollview in the storyboard, it doesn't work to just scroll on it with the mouse if thats the way, have my way to set this up maybe disabled this..?
And when thinking about it: If I want the scrollview to be smaller than the View itself, I should put it inside a view in the storyboard, right? So if you know a tutorial on how to do that or if you can describe the procedure, feel free to.

#Synthesize IBOutlet (UIScrollView) not working

This is about an outlet not synthesising correctly (UIScrollView)
In one particular case, i have an interface declared as:
#interface VC_Create_Preview : UIViewController <UIScrollViewDelegate> {
UIScrollView *scrollView;
}
#property (nonatomic, retain) IBOutlet UIScrollView *scrollView;
And in the implementation....
#synthesize scrollView;
But in debug mode i see that my self->scrollView always has a 0x0 next to it.
Performing operations like
CGRect frame = scrollView.frame;
always returns a origin, height, width of zero (i suspect because it did not synthesise correctly)
Does 0x0 mean that it does not point to any location in memory?
Does this mean that it did not synthesize correctly?
Could it be that there is a broken link somewhere from the outlet to the scrollview in IB?
Cheers
Kevin
Make sure that you actually connected a UIScrollView to the outlet.
Keep in mind that scrollView won't be set until after the view has been loaded from the nib.
0x0 means a null pointer, you probably have not tied the scrollView to a scroll view in IB...This means having the viewControllers nib have a scrollView in its view and tied to the outlet.
If you want to work with outlets and use there real size that user will see (include navigation bar, tab bar, etc.) you must implement all UI changes at viewWillAppear or viewDidAppear.
Read more about stages of loading view from nib.
Try removing local declaration of scrollview i.e.
#interface VC_Create_Preview : UIViewController <UIScrollViewDelegate> {
UIScrollView *scrollView;//remove this
}
It may help you. Also while allocating use _scrollView instead of scrollView.
Be sure that you are using the correct class in your code, for example, the first UIViewController you drop into storyboard will have the generic "whateveryourprojectiscalled" UIViewController.
However, the problem for me was that I then had that linked to several other UIViewController, none of which had there own class declared, so the scroller outlet I was writing, is only showing up on the main original UIViewController which is not where I needed it to be. So once I wrote a Custom Class name, and then re wrote the code to accommodate that. The outlet appeared perfectly and worked fine.

How to add fixed bar displaying today's date below navigation bar?

I have a uitableview with a tabbar and a navigation bar. Just below the navigation bar, I want another fixed bar, sticking to the navigation bar even while scrolling through the table, which will display today's date. I know that the displaying the date involves NSDateFrmatter and such, so converting NSDates is not the issue. The issue is bar itself. How can I add such a fixed bar, and add a title (which will be the dates) to it?
There's a couple of ways you could achieve this, but here's what I'd do: first, create a UIViewController subclass, and add a UIToolbar instance to the controller's view with a frame of CGRectMake(0.f, 0.f, 320.f, 44.f). Then, create a UITableView instance, and also add it to the view with a frame of CGRectMake(0.f, 44.f, 320.f, self.view.frame.size.height - 44.f).
Instead of using UITableViewController you will have to subclass UIViewController and put a UIView with you date at the top and then the tableview below it. And set it up as the delegate and data source for the table in the header file and the outlets in Interface Builder.
#interface YourViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
#property (nonatomic, retain) IBOutlet UITableView *tableView;
The only other thing that UITableViewController provides for you that you may need to implement yourself is it will automatically clear the table’s current selection when it receives a viewWillAppear: message.

Add subview to tableview which doesn't scroll

I'm using a UITableViewController and want to add a searchbar.
My options are [self.tableview addSubview:searchBar] or self.tableview.tableHeaderView = searchBar
Both options will scroll the searchbar along the rest of the tableview, which I understand. But is there a way to lock elements up, instead of using a UIViewController or changing the frame origin on scroll?
I'm thinking of a way to get above the current view hierarchy and add a subview onto that.
I tried the opposite approach, to add a view to the superview and bring that to front
[[self.tableView superview] addSubview:searchBar];
[[self.tableView superview] bringSubviewToFront:searchBar];
}
but it didn't work.
UITableViewControllers are UIViewControllers that have their main view property being an UITableView. Thus this UITableView do takes all the screen.
The approach you are looking for is to use a standard UIViewController whose view is a standard UIView, and add your UISearchBar and the UITableView as a subview to it in IB.
To do this, simply:
Change the class of your view controller and instead mention that it conforms to the tableview-associated protocols : change #interface UITableViewController to #interface UIViewController <UITableViewDelegate, UITableViewDataSource>
Add a #property(nonatomic, retain) IBOutlet UITableView* tableView property to your header file, and the associated #synthesize tableView; statement in the implementation. Don't forget to set this property back to nil (self.tableView = nil) in your dealloc for good memory managment
Link your UITableView instance in InterfaceBuilder to this newly created IBOutlet.
Thus you still have a UITableView but this won't be the main view that takes all your screen; instead you can layout your tableView like you want and make it take only a part of your screen, and position the UISearchBar above it.
Another approach would be to use the UISearchDisplayController to manage your UISearchBar.