I have a probably nub question but i just can't get around this.
I have a UIScrollview on the top of the screen, below it there is a UITableView.
both are on my InterfaceBuilder, not done programmatically
and declared on my .h as:
#interface RootViewController : UIViewController <UIScrollViewDelegate, IconDownloaderDelegate>
{
IBOutlet UIScrollView *scrollview;
}
etc.
Inside the UIScrollView i have a long tabbar also in IB mi code is as follows for this:
[scrollview setScrollEnabled:YES];
[scrollview setContentSize:CGSizeMake(1100, 29)];
Everithing works perfectly the tabbar works and moves etc.
the problem is that when implementing scrollViewWillBeginDragging
it only registers the scrolling on my UITableView and not on the scrollview.
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
NSLog(#"done");
}
What am i doing wrong??
Thanks in advance!
You have to set the delegate to the class where you implement the delegate methods.
scrollview.delegate = self;
add [scrollview SetDelegate:self]; in the place you add scrollview
Related
i read all the other replies for similar question but my project still don't work.
Any help?
This is my project.
----------------> viewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController{
IBOutlet UIScrollView *scroll;
IBOutlet UIImageView *imagev;
}
----------------> viewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
imagev.image = [UIImage imageNamed:#"ka.jpg"];
[scroll setContentSize:CGSizeMake(700, 700)];
[scroll setScrollEnabled:TRUE];
[scroll setShowsVerticalScrollIndicator:YES];
[scroll setShowsHorizontalScrollIndicator:YES];
}
#end
everything looks fine but the scrollview won't scroll..
EDIT: as they suggested here, the problem was Autolayout. with that i fixed the scrollview
I've got a fix for you, and you can continue to use autolayout.
Implement the following method in "ViewController.m"
- (void)viewDidLayoutSubviews
{
[scroll setContentSize:CGSizeMake(700, 700)];
}
And you can remove [scroll setContentSize:CGSizeMake(700, 700)]; from the -viewDidLoad method.
This will fix it for you, and you can continue to use auto-layout. Auto-layout is a bit dodgy in iOS 6. But it is apparently much better in iOS 7.
I believe Autolayout is causing the problem. Try turning it off.
Select the ViewController in the Storyboard or NIB
Click the 'File Inspector' tab on the right hand side of your Xcode window
Under the 'Interface Builder Document' section, uncheck 'Use Autolayout'
Objective - C
you can use this lines of code into your *.m file's - (void)viewDidLoad{} function:
[scroll setContentSize:CGSizeMake(320, 800)];
[scroll setScrollEnabled:TRUE];
[scroll setShowsVerticalScrollIndicator:NO];
[scroll setShowsHorizontalScrollIndicator:YES];
for this you need to take an IBOutlet property of UIScrollView into your *.h file this way:
IBOutlet UIScrollView *scroll;
And connect this from Storyboard.
Or,
You can use this method into your *.m file:
-(void)viewDidLayoutSubviews {
[scroll setContentSize:CGSizeMake(320, self.view.frame.size.height* 1.5)];
// this will pick height automatically from device's height and multiply it with 1.5
}
This both solution works for me in xcode-5, xcode-6, xcode-6.1, xcode-6.2
Swift:
You can use this swift code for similar type of issue:
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
scrollView.contentSize = CGSize(width:10, height:10)
}
I'm trying to set up a scrollView in an app using storyboarding. I have done everything correctly but the scrollview won't scroll in simulator or on iPhone.
MoreViewController.h
#property(nonatomic, retain) IBOutlet UIScrollView *moreScroll;
MoreViewController.m
-(void)viewDidLoad{
[moreScroll setScrollEnabled:YES];
[moreScroll setContentSize:CGSizeMake(1220, 354)];
}
I have connected the scrollView to the files owner, can someone help please
Thanks in Advance
With autolayout is there a new method - (void)viewDidLayoutSubviews
Here is a quick info:
Notifies the view controller that its view just laid out its subviews.
When a view’s bounds change, the view adjusts the position of its subviews. Your view controller can override this method to make changes after the view lays out its subviews. The default implementation of this method does nothing.
You should be fine if you add this:
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubViews];
[moreScroll setContentSize:CGSizeMake(1220, 354)];
}
Setting an scroll view’s scroller style sets the style of both the horizontal and vertical scrollers. If the scroll view subsequently creates or is assigned a new horizontal or vertical scroller, they will be assigned the same scroller style that was assigned to the scroll view..
You should be if you add this lines in your code:
This line in .h file
#interface Shout_RouteView : UIViewController<UIScrollViewDelegate>
{
}
#property (retain, nonatomic) IBOutlet UIScrollView *scrollViewMain;
This lines copy in .m file
-(void)viewWillAppear:(BOOL)animated {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
scrollViewMain.frame = CGRectMake(0, 0, 768, 815);
[scrollViewMain setContentSize:CGSizeMake(768, 1040)];
}else {
scrollViewMain.frame = CGRectMake(0, 0, 320, 370);
[scrollViewMain setContentSize:CGSizeMake(320, 510)];
}
}
I suggest that you try to pust the content setting code into the viewWillAppear or viewDidAppear method. Its always best not attempt changing UI features before it is ready for display.
I am creating an app with multiple UIViewController, they have common menu and toolbar in header. i have created a uiviewcontroller with nib for top UIToolBar with some UIToolBarButtons. I am calling in another UIViewController, my problem is this that UIToolBar is displaying but any of UIToolbar button is not clickable now, they are not working. so it only showing the view which is not working at all.
Please see UIView UserInterfaceEnabled or not. if not then just write below code in your viewdidload
self.view.userInteractionEnabled = YES;
OR also try this
[self.view bringSubviewToFront:youtoolbar];
just try this code something skip you from your code
[yourBarButton setTarget:self];
[yourBarButton setAction:#selector(yourBtnClicked:)];
[yourToolBar setUserInteractionEnabled:YES];
[self.view setUserInteractionEnabled:YES];
[self.view bringSubviewToFront:yourToolBar];
UPDATE:
For use this UIToolBar to every UIViewController, just add it in window and set method in AppDelegate class also...
hope this help you...
Try this.. You remove your toolbar in viewWillAppear and add it again like
(void)viewWillAppear:(BOOL)animated
{
[yourtoolbar_reference removeFromSuperview];
[self.view addSubview:yourtoolbar_reference];
}
In my view I want to add a target which should be fired when I click the view. I can do the same through IB or I have done it for buttons even in code. However I have no idea how to do it for UIView programatically.
Anyone has done that before.
Help me.
For clicking a UIView you have to use UIGestureRecognizer or UITouch. This would only help in prompting an action. The UIButton has a selector method whereas the UIView does not have any such method. Also , this is same for UIImageViews etc also.
You can acheive this using UIGestureRecognizer.
Step 1:
Add your UIView as a property in your viewcontroller
#property (strong, nonatomic) IBOutlet UIView *yourView;
Step 2:
Set UIGestureRecognizer for your UIView.
- (void)viewDidLoad {
[super viewDidLoad];
UIGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleGesture:)];
[self.yourView addGestureRecognizer:gesture];
}
Step 3:
Handle the click on UIView.
- (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer {
//to get the clicked location inside the view do this.
CGPoint point = [gestureRecognizer locationInView:self.yourView];
}
Remember that A UIGestureRecognizer is to be be used with a single view.
I have a simple ViewController that looks like this:
#interface MyViewController : UIViewController<UIScrollViewDelegate> {
UIScrollView *scrollView;
UILabel *label;
}
...
#property stuff
...
Now, what I'm trying to do with this Controller is have a ScrollView handle a really large label of text that I have. So in the viewDidLoad method of MyViewController.m I have:
scrollView.contentSize = CGSizeMake(1000,1000);
scrollView.delegate = self;
scrollView.clipsToBounds = YES;
[self.view addSubview:scrollView];
And I get a blank screen that I cannot scroll around on. It's just a white screen. Before adding the label part, I thought I would try to set up the scroll view first, and this is not even working. Shouldn't I see some scroll bars when I move my fingers around? How do I set up the scroll view so that it contains a label?
Thanks!
The scrollView wont be scrollable until you actually place content inside it which exceeds its frame. So, add your label to the scrollview and it should become scrollable.