can not move buttons - ios

I have a little problem that my buttons doesn't move when I am using a code that should move the button.
ViewControlle.h:
#property (strong, nonatomic) IBOutlet UIButton *button1;
#property (strong, nonatomic) IBOutlet UIButton *button2;
ViewController.m:
#implementation GameViewController
#synthesize button1,button2;
code which should move the buttons:
button1.center=CGPointMake(button1.center.x, button1.center.y-10);
button2.center=CGPointMake(button2.center.x, button2.center.y+10);
why does the code not work or am I doing something wrong?

Because autolayout did not happen before view did load it will reset your locations.
when - (void)viewDidLayoutSubviews gets called its done so place your code here.

If you are using AutoLayout for ViewController than It's not work.
Uncheck the AutoLayout for ViewController.

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

Xcode 4 storyboard, textfields not wanting to connect to IBOutlet

So in the storyboard i have a UIViewController class called FormViewController. I set the ViewController in the storyboard to use that:
I then have the three text fields in the header file:
#import <UIKit/UIKit.h>
#interface FormViewController : UIViewController
#property (strong, retain) IBOutlet UITextView *firstName;
#property (strong, retain) IBOutlet UITextView *lastName;
#property (strong, retain) IBOutlet UITextView *email;
- (IBAction) save:(id)sender;
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender;
#end
However, when i try to connect the ones in the storyboard to the view controller, it doesnt pop up.
Any ideas?
UITextField and UITextView are two very different classes—you have created UITextField instances but your outlets are typed as UITextView.
Just change your outlet types to UITextField and all should be well!
(UITextView, for the record, is a scrolling, often editable field, more like a word processor.)

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

button not displaying in simulator

Edit re-wrote question:
Hi there I'm working on another student's project (taking over) there's no main storyboard, only a viewonctroller.Xib under resources a Viewcontroller.h and .m
I'm trying to add new buttons but they aren't displaying. I linked the new buttons to the viewcontroller.h and .m file with no actual code in the code such as
-(IBAction)button { empty }
in the .h file it's
IBOutlet UIButton *button;
The button's not displaying in the simulator however, Also the former student has every button in the app displayed in the same window and just uses the setHidden function to distinguish between menu's in game. I thought that maybe the button was just behind other buttons but when I go to editor-> send to front the option is grayed out.
edit Sample code of ViewController.H
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <QuartzCore/QuartzCore.h>
// Game Center -- ignore and or delete
#import <GameKit/GameKit.h>
#import "GameCenterManager.h"
#interface SideWinderViewController : UIViewController <AVAudioPlayerDelegate, /*ADBannerViewDelegate,*/ UIActionSheetDelegate, GKLeaderboardViewControllerDelegate,
GKAchievementViewControllerDelegate, GameCenterManagerDelegate> {
// Game Center
GameCenterManager *gameCenterManager;
int64_t currentScore;
NSString* currentLeaderBoard;
IBOutlet UILabel *currentScoreLabel;
// End Game Center
IBOutlet UIImageView *ballpng;
IBOutlet UILabel *displaycredit2;
IBOutlet UILabel *displaycredits;
IBOutlet UIButton *easy;
IBOutlet UIButton *medium;
IBOutlet UIButton *hard;
IBOutlet UILabel *displayhighscore;
IBOutlet UILabel *Howtoplay;
IBOutlet UIButton *back;
IBOutlet UIButton *info;
IBOutlet UIButton *playbutton_mainmenu;
IBOutlet UIImageView *winder1;
IBOutlet UIImageView *socket1;
IBOutlet UIImageView *wheelcontrol2;
IBOutlet UILabel *seconds;
IBOutlet UILabel *scoreLabel;
IBOutlet UIButton *Restart;
IBOutlet UIButton *HIGHSCORE;
IBOutlet UIButton *pausebutton;
IBOutlet UIButton *resumebutton;
IBOutlet UIButton *gameStartButton;
IBOutlet UIImageView *mainmenu;
IBOutlet UIButton *credits;
IBOutlet UIButton *returnt
sample code for .m
#import <UIKit/UIKit.h>
#import "SideWinderViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "Ball.h"
#import <AVFoundation/AVAudioPlayer.h>
// Game Center -- ignore and or delete
#import "AppSpecificValues.h"
#import "GameCenterManager.h"
// End Game Center
#implementation SideWinderViewController
-(void)viewDidLoad {
[Restart setHidden:NO];
...
Thats enough to show a button
Check
Xib shown is the right one
Is tht button is covered by some other view added via code
Is the button property hidden checked or unchecked
Check button Frame

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.

Resources