iOS setting a UIScrollView variable from IB shows as nil - ios

At the moment I have a UIViewController subclass with a UIScrollView and a UIView inside of it. Below is a snippet of code from the class:
.h
#import <UIKit/UIKit.h>
#interface Scroller : UIViewController <UIScrollViewDelegate>
{
UIScrollView *scrollView;
UIView *testView;
}
#property (retain, nonatomic) IBOutlet UIScrollView *scrollView;
#property (retain, nonatomic) IBOutlet UIView *testView;
#end
Inside the IB I link the UIScrollview to my variable, but when I get to the .m and try setting my scrollview contentSize it shows the scrollView as being nil.
.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
// Initialize of scrollView
scrollView.contentSize = CGSizeMake(500, 500);
scrollView.delegate = self;
}
Am I missing an import or anything to get this to be properly allocated?
Edit
It may help to know, but if I try to debug the issue and in the lldb check the value of scrollView I get a EXC_BAD_ACCESS error if I try to continue in the code.

try
//.h
#interface Scroller : UIViewController <UIScrollViewDelegate>
{
}
#property (retain, nonatomic) IBOutlet UIScrollView *scrollView;
#property (retain, nonatomic) IBOutlet UIView *testView;
//.m
[self.scrollView setContentSize:CGSizeMake(500, 500)];
just to clarify
scrollview without the self. was looking at the iVar - which I assume you had not alloc-ed/init-ed.
The #property IBOutlet connected to your nib is NOT the same as that iVar. In effect you have two variables of the same name - if you get rid of those iVars the property will still get allocated and initialised for you when the XIB is loaded.

The issue wasn't related to the code, but the debugger itself. I tried doing this in xCode 4.3.1 and was debugging through the application and saw that the proper fields weren't being set both in the xib and in the code. I deleted everything and opened up xCode 4.2 and tried in there and everything worked nicely. After testing in 4.2 I moved to 4.3.1 where it asked me to switch from the GDB to the LLDB. I guess it was just paranoia on my end for not seeing proper results showing up.

Related

UIScrollView not responding in xcode8, ios10 when it was OK in Xcode 7 ios9

Inside my app, I have a UIViewController which is composed of the following elements:
Two buttons and a UILabel on the top part of it
A UISCrollView which contains different elements, UILabels, Buttons and more.
I include a screenshot for you to understand the structure.
When compiled in Xcode 7 with iOS 9 SDK everything has been working properly. But now I am trying to update the app for it to work in iOS 10 and the screen does not respond when trying to scroll. The two buttons outside the UIScrollView still are working OK.
The only warning I am receiving when running on the iPhone is:
[LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"",
""
)
IB also tells me that there is a mistake with the constraints (red indicator). It tells that ScrollVertical (UISCrollView) need constraints for: Y position or Height. But I'm quite sure that this message was shown in xcode7-ios9, when everything worked properly.
Any idea what is happening? Any idea would be appreciated, since I have been struggling with this for a day.
This arre the constraints expanded:
Thanks a lot
Maybe you should expend the Constraints node in your view hierarchy, and capture the constraints your have defined in Xcode, and paste it here. That would be helped for issue tracking.
Same problem here, but with a twist. On first startup of subscreen scrolling won't work. After rotating the device it works fine. It makes no difference if it starts on portrait or landscape oritation. after a rotating the app works fine. No problems with IOS9 and IOS8.
#import <QuartzCore/QuartzCore.h>
#import "ApDetailTableViewController.h"
#import "ApMailViewController.h"
#import "ApApplicatieData.h"
#import "ztatz_constants.h"
#import "ztatz_macro.h"
#interface ApDetailTableViewController ()
#property (weak, nonatomic) IBOutlet UIView *contentUIView;
#property (weak, nonatomic) IBOutlet UIScrollView *apUIScrolView;
#property (weak, nonatomic) IBOutlet NSLayoutConstraint *contentViewHeightConstraint;
#property (weak, nonatomic) IBOutlet UIView *lastSeperatorView;
#property (weak, nonatomic) IBOutlet UILabel *applicatienaam;
#property (weak, nonatomic) IBOutlet UILabel *san;
#property (weak, nonatomic) IBOutlet UILabel *beschrijving;
#property (weak, nonatomic) IBOutlet UILabel *status;
#property (weak, nonatomic) IBOutlet UILabel *updatetime;
#property (weak, nonatomic) IBOutlet UILabel *afdelingsnaam;
#property (weak, nonatomic) IBOutlet UILabel *contactpersoon;
#property (weak, nonatomic) IBOutlet UILabel *email;
#property (weak, nonatomic) IBOutlet UILabel *controledatum;
#end
#implementation ApDetailTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.applicatienaam.text = self.apDataForDetails.applicatienaam;
self.san.text = self.apDataForDetails.san;
self.beschrijving.text = self.apDataForDetails.beschrijving;
self.status.text = self.apDataForDetails.status;
self.updatetime.text = self.apDataForDetails.updatetime;
self.afdelingsnaam.text = self.apDataForDetails.afdelingsnaam;
self.contactpersoon.text=self.apDataForDetails.contactpersoon;
self.email.text=self.apDataForDetails.email;
self.controledatum.text=self.apDataForDetails.controledatum;
// start a top of scroll view
self.automaticallyAdjustsScrollViewInsets = NO;
}
-(void) viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
// limit the slack space at the end of the scroll view.
DLog(#"y = %f\n", self.lastSeperatorView.frame.origin.y);
self.contentViewHeightConstraint.constant = self.lastSeperatorView.frame.origin.y+4;
}
#end

Connecting IBOutlet to UITextView makes UITextView invisible

I have checked thoroughly for a solution to this (notably here: Can't connect IBOutlet in Interface Builder) but cannot see the solution. I have a UITextView that I am using as a text area in a form. I have connected it to this class member in IB:
IBOutlet UITextView *notes;
here is my .h
#import <UIKit/UIKit.h>
#import <AddressBookUI/AddressBookUI.h>
#interface U2MIDetailController : UIViewController <UITextFieldDelegate, UITextViewDelegate> {
IBOutlet UIButton *confirmButton;
IBOutlet UITextView *notes;
}
#property (nonatomic, retain) IBOutlet UITextView* notes;
#property ABRecordRef personObject;
#property (strong, nonatomic) IBOutlet UIScrollView *scroller;
#end
and my .m, the relevant bits:
#synthesize notes;
- (void)viewDidLoad
{
[super viewDidLoad];
//set up delegates for keyboard hiding
notes.delegate = self;
notes.text = #"Notes";
...
}
In the links I've found some have solved this issue by checking the File's Owner "Class" attribute on the Identity inspector. How do I do that? I have attached a pic of the hierarchy which looks correct to me, the identity inspector doesn't jump out at me either as having any suspicious properties.
Here is a shot of the storyboard:
and here is how it looks int he simulator:
check your scrollview frame either it is fit to frame or not. put blackground color you know where you did mistake

ios, scrolling screen with a few objects without zooming. Attempt 2

#everybody
Hi guys!
I've not found out the solution to my problem, so I decide to ask the question again.
First attempt is there LINK
I have screen w/ a few labels. Each of them might be from 1 to a dozen lines. So some times all content not to fit on screen so scrolling is necessary.
All seem to be easy and there are a lot of tutorials how to do it. Just set contentSize bigger than frame. But my problem that scrolling works only when I zoom in screen. Setting contentSize doesn't give any effect.
#interface OMSScroolViewController : UIViewController <UIScrollViewDelegate>
#property (strong, nonatomic) IBOutlet UIScrollView *scroll;
#property (strong, nonatomic) IBOutlet UILabel *label1;
#property (strong, nonatomic) IBOutlet UILabel *label2;
#end
and implementation
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
scroll.minimumZoomScale=1.0;
scroll.maximumZoomScale=1.0;
[scroll setContentSize:CGSizeMake(320, 1690)]; // constants for simplicity
scroll.delegate=self;
}
I've also tried to use a extra UIView inside UIScroolView but w/o any success.
Moreover I found a few threads there on stackoverflow w/ the same problem, unfortunately w/o solutions.
Thanks for cooperation.

ios, scrolling screen with a few objects without zooming

I have screen w/ a few labels. Each of them might be from 1 to a dozen lines.
So some times all content not to fit on screen so scrolling is necessary.
All seem to be easy and there are a lot of tutorials how to do it.
But my problem that scrolling works only when I zoom in screen. Setting "contentSize" doesn't give any effect.
#interface OMSScroolViewController : UIViewController <UIScrollViewDelegate>
#property (strong, nonatomic) IBOutlet UIScrollView *scroll;
#property (strong, nonatomic) IBOutlet UILabel *label1;
#property (strong, nonatomic) IBOutlet UILabel *label2;
#end
and implementation
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
scroll.minimumZoomScale=1.0;
scroll.maximumZoomScale=1.0;
[scroll setContentSize:CGSizeMake(320, 1690)]; // constants for simplicity
scroll.delegate=self;
}
any suggestions?
thanks in advance.
Although not technically required, I've never had UIScrollView to work properly without using a content view to wrap the scrollable content. Once you wrap all your labels in a single view, your code should work without issue.

Confusion Regarding UIScrollView and AutoLayout

I have looked around many different threads over the same issue and can't seem to grasp what is going on here. I created a very basic and simple project. What I want to happen is for a bunch of elements to be inside of a scroll view that scrolls properly. These elements may include a UITableView that scrolls independently (or not). Here is how I set up my basic project:
Running this in the simulator will result in a view that doesn't scroll. This is expected as there is more than enough room for all of the elements. I then changed the size of UIScrollView like so:
Running this in the simulator results in a smaller view that will not scroll. I assume I am not doing this the correct way. Here is the code I have most recently tried:
ViewController.h
#interface ViewController : UIViewController <UIScrollViewDelegate>
#property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
#property (strong, nonatomic) IBOutlet UIButton *buttonOne;
#property (strong, nonatomic) IBOutlet UIButton *buttonTwo;
#property (strong, nonatomic) IBOutlet UIButton *buttonThree;
#property (strong, nonatomic) IBOutlet UIButton *buttonFour;
#end
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.
[self.buttonOne setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.buttonTwo setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.buttonThree setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.buttonFour setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.scrollView setTranslatesAutoresizingMaskIntoConstraints:NO];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Any help would be greatly appreciated.
The problem is that when you change the size of the scroll view in interface builder, you are also setting the content's size to the same as the frame size.
You can manually increase the content size of the scroll view in code so that you can scroll it like this:
// scrollView is an outlet to your scroll view
// Add 200 points to the bottom of the scroll view
[self.scrollView setContentInset:UIEdgeInsetsMake(0, 0, 200, 0)];
Though, you probably don't need to do this as long as you draw the sub view at full size, and make it a sub view of some other view, and let it automatically re-size itself.

Resources