Menu
  • HOME
  • TAGS

Subview content being mysteriously offset in Interface Builder?

Tag: xcode,interface-builder,uicollectionview,uitextview,offset

I'm experiencing a weird behavior in Interface Builder. I almost feel like it's a glitch, but I'm hoping that I'm just misunderstanding something, or that someone knows what weird AutoLayout behavior I'm experiencing, or something. I'll try to describe it as best I can...

I've got a ViewController in Interface Builder, with nothing but a UITextView. Nothing unusual about the TextView, I just dragged it in from the sidebar, and it's the first thing I added. But here's the thing: the text is offset by about 50 points. There's nothing in the Size Inspector that would explain it, the text is just spaced down. BUT, if I click and drag it around, the text pops back up to the top. Then I drop it in a new place, and the text is offset again.

Here's where it gets really weird: if I drag a UICollectionView into that same ViewController, it's fine (the default cell is right up in the top left corner), but as soon as I delete the TextView, the default cell gets moved 50 points down in the CollectionView! Now I have a CollectionView with an offset cell, and if I drag a new TextView back on, it's fine, but deleting the CollectionView adds the offset back to the new TextView! The location of the views is irrelevant (either at the time of adding or later), the older view will always be offset.

And, just for an extra dose of weird: whichever view is offset, if I click and drag it to move it around, the other view will be offset until I drop it in its new location. Oh, and deleting the ViewController entirely and starting again does nothing. The behavior remains.

What black magic is this?! This is the 8th ViewController I've added to my Storyboard (12th if you include abstract ViewControllers like TabBarControllers etc), and none of them had this issue. Why would this forced-offset exist, and how do I stop it? Is this some weird permutation of AutoLayout or something? Or does this sound like a genuine glitch, and I should post on a tech support forum?

EDIT: Just to be clear: the offset does appear when the app is run in the Simulator. IB shows that the frame isn't changing, the content is being offset within the frame, but whatever it is, it DOES show up in the final app.

Best How To :

The answer turned out to be turning off "Adjust Scroll View Insets" on the ViewController.

Sort of a weird behavior for the ViewController to present like that, adjusting a single ScrollView without any regard for its position or size, but at least it was an easy fix.

enter image description here

How to use existing SQLite database in swift?

ios,database,xcode,sqlite,swift

First add libsqlite3.dylib to your Xcode project (in project settings/Build Phases/Link Binary with Libraries), then use something like fmdb, it makes dealing with SQLite a lot easier. It's written in Objective-C but can be used in a Swift project, too. Then you could write a DatabaseManager class, for example... import...

Redundant conformance error message Swift 2

xcode,swift

You'll get that error message in Xcode 7 (Swift 2) if a subclass declares conformance to a protocol which is already inherited from a superclass. Example: class MyClass : CustomStringConvertible { var description: String { return "MyClass" } } class Subclass : MyClass, CustomStringConvertible { override var description: String {...

PFUser not unwrapped - swift

ios,xcode,swift

Here is explanation: What is an "unwrapped value" in Swift? PFFacebookUtils.logInWithPermissions(["public_profile", "user_about_me", "user_birthday"], block: { user, error in if user == nil { println("the user canceled fb login") //add uialert return } //new user else if user!.isNew { println("user singed up through FB") //get information from fb then save to...

Swift timer in milliseconds

xcode,swift

As Martin says in his comment, timers have a resolution of 50-100 ms (0.02 to 0.1 seconds). Trying to run a timer with an interval shorter than that will not give reliable results. Also, timers are not realtime. They depend on the run loop they are attached to, and if...

Xcode referencing old copies of files

ios,objective-c,xcode,file-management

Xcode does not keep the source files, it just points to them. Most likely you are editing a copy Xcode is not using. In Xcode check the location of the file it is using: ...

Command-Line Testing Using Cocoa Touch

xcode,cocoa,kif

After checking several options, I have decided to use xctool because this is a recommended tool when the tests have been done using KIF. At the beginning I had some trouble trying to run the test, but after reading other posts I have use the following commands: For running all...

Put Swipe Gesture over UIWebView to Get Scroll Direction in IOS

ios,xcode,scroll,uiwebview,swipe

This is how I implemented swipe gesture in UIWebView. Add <UIGestureRecognizerDelegate> protocol to ViewController.h In ViewDidLoad Method add the following code: UISwipeGestureRecognizer * swipeGestureDown = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeDown)]; swipeGestureDown.numberOfTouchesRequired = 1; swipeGestureDown.direction = UISwipeGestureRecognizerDirectionDown; swipeGestureDown.delegate = self; [self.webView addGestureRecognizer:swipeGestureDown]; Add Delegate method in ViewController.m :...

Switch between views using a Tabbar

ios,xcode,swift,ios8

I've fix my problem. I've originally put the line of code bellow on the viewDidLoad() of my controller : tabBarController.selectedViewController = mySecondViewController After moving this line in a different methode, call by a simple button, that worked......

control may reach end of non-void function xcode

c++,xcode,visual-studio-2012

When writing something like Type func() { ... } The compiler expect you to return an object of type Type in every paths of the function, which is not what you do here. Or your LOG function return an A object, which I doubt, and you should write return LOG(),...

TableViewCell overlaps text

ios,xcode,swift,uitableview,overlap

I can fix the problem. In the storyboard, the label have unchacked "Clears Graphics Context". I checked and for now it solved! Thanks for the help!

New warnings in iOS9

xcode,ios9

You library was compiled without bitcode but the bitcode option is enabled in your project settings. Say NO to Enable Bitcode in your target Build Settings and the Library Build Settings to remove the warnings. ...

Turn a switch Off or On on the basis of another switch state

ios,xcode,uiswitch

first of all you need to create IBOutlet of both UISwitch in your header .h file @property (strong, nonatomic) IBOutlet UISwitch *isMale; @property (strong, nonatomic) IBOutlet UISwitch *isFemale; then in your IBAction do as follow. - (IBAction)isMale:(id)sender { if ([sender isOn]) { [_isFemale setOn:NO animated:YES]; } else { // do...

AutoLayout complains about constraints for 2 UITextFields with no borders

ios,xcode,swift,autolayout,nslayoutconstraint

"Add Missing Constraints" is not always a good idea to add constraints..rather you should always prefer to add constraints manually... Here is the image for your UI...I used wAnyhAny layout as it is good practice for add constraints for universal devices... I used simply width constraint for textfield, rather you...

How do you work with views in MainMenu.xib?

objective-c,xcode,osx,cocoa

So the default is that your main application window is an outlet in the app delegate. You should keep MainMenu.xib's owner as the app delegate. A common alternative, if you are creating your own custom window controller, is to create a property in the AppDelegate of type CustomWindowController, then in...

Extracting values from NSDictionary to individual variables

ios,xcode,swift

The problem is here, you are declaring record as a String, previously it was NSDictionary and due to scope the record in record["record_id"] is String not NSDictionary. Quick fix is to change the name as I did let time: String = record["time"] as! String let record1: String = record["record"] as!...

How do I make is so the entered number is mulitplied by the slider number

xcode,swift

Thats because your slider.value returns a Float. You are trying to convert the result of it but you need to convert just the slider.value to Int to multiply it by numbers which is an Int. Try like this: Note: As mentioned by Josh you need also to unwrap toInt() optional...

How can I display the time offset (years, months, weeks, …) from two dates at my labels?

ios,xcode,swift

I have created a new extension to output the offset components as string for you: import UIKit extension NSDate { func yearsFrom(date:NSDate) -> Int{ return NSCalendar.currentCalendar().components(.CalendarUnitYear, fromDate: date, toDate: self, options: nil).year } func monthsFrom(date:NSDate) -> Int{ return NSCalendar.currentCalendar().components(.CalendarUnitMonth, fromDate: date, toDate: self, options: nil).month } func weeksFrom(date:NSDate) -> Int{...

Getting video from Asset Catalog using On Demand ressources

ios,xcode,xcode7,ios9,asset-catalog

I think its not possible to use Asset Catalog for video stuff, Its simplify management of images. Apple Documentation Use asset catalogs to simplify management of images that are used by your app as part of its user interface. An asset catalog can include: Image sets: Used for most types...

Transferring an Xcode project to another computer with all files/frameworks

ios,xcode,frameworks,transfer,projects

Try transferring everything from plists to the storyboard. I did this with a friend of mine and it only took about 20 minutes for the code to build and run successfully on his own laptop. the biggest issue is going to be transferring the files that Xcode is going to...

How can I fix crash when tap to select row after scrolling the tableview?

ios,xcode,swift,uitableview,tableviewcell

Because you are using reusable cells when you try to select a cell that is not in the screen anymore the app will crash as the cell is no long exist in memory, try this: if let lastCell = self.diceFaceTable.cellForRowAtIndexPath(lastIndexPath) as! TableViewCell{ lastCell.checkImg.image = UIImage(named: "uncheck") } //update the data...

Xcode UIWebView not changing page with changed URL

ios,objective-c,xcode,uiwebview

[self.webView reload] - will reload the current page. This is probably happening before the loadRequest has finished. Try removing this line. Also, @joern's comment is correct; the 'event' is the user making a pan gesture. Lose the timer....

Read plist inside ~/Library/Preferences/

objective-c,xcode,osx

You need to use NSString method: stringByExpandingTildeInPath to expand the ~ into the full path. NSString *resPath = [@"~/Library/Preferences/" stringByExpandingTildeInPath]; NSLog(@"resPath: %@", resPath); Output: resPath: /Volumes/User/me/Library/Preferences ...

canEvaluatePolicy Extra argument 'error' in call Swift Xcode 7

ios,xcode,ios8,xcode7

As mentioned in Using Swift with Cocoa and Objective-C, all Objective-C methods that use NSError to return an error object will now throw when called from Swift 2.0, so you need to use: do { try method() } catch let error as NSError { reportError(error) } Removing the reference to...

change Auto Layout dynamically

ios,iphone,xcode,storyboard,autolayout

Just give top, left , right, height and equal width constraints to all label.... ...

Build error after I localized Info.plist

ios,objective-c,xcode,swift,localization

Roll back those changes, add a InfoPlist.strings file to your project, localize it and then add the needed keys to it. For example: "CFBundleDisplayName" = "App display name"; "CFBundleName" = "App bundle name"; ...

Swift 2 : NSData(contentsOfURL:url) returning nil

ios,json,xcode,foundation,swift2

I would expect it to work in the terminal, since what you're seeing here is likely not a bug in Swift or Cocoa Touch, but the side effects of a new feature in iOS 9 called App Transport Security. What this means is that by default, iOS will not permit...

best way to create a mat from a CIImage?

c++,xcode,osx,opencv,opencv3.0

Found a solution to get rid of the crash: use createCGImage:fromRect to skip the NSBitmapImageRef step: - (void)OpenCVdetectSmilesIn:(CIFaceFeature *)faceFeature usingImage:ciFrameImage { CGRect lowerFaceRectFull = faceFeature.bounds; lowerFaceRectFull.size.height *=0.5; CIImage *lowerFaceImageFull = [ciFrameImage imageByCroppingToRect:lowerFaceRectFull]; // Create the context and instruct CoreImage to draw the output image recipe into a CGImage if( self.context...

When trying to get dynamically created UILabel to wrap, text disappears

xcode,swift,word-wrap,cgrect,sizetofit

Changing the position of sizeToFit() after assigning text did the job as suggested by Bartlomiej above

Coco2dx - Changing To Background Image

ios,iphone,xcode,xcode6,ios-simulator

Create and add a CCSprite: CCSprite *bg = [CCSprite spriteWithFile:@"bg.png"]; bg.tag = 1; bg.anchorPoint = CGPointMake(0, 0); [self addChild:bg]; ...

How can I find out the Objective-C generics type?

ios,objective-c,xcode,generics

The lightweight generics introduced in Xcode 7 are just compile time hints to help the compiler raise warnings, but at run time you get the same old behavior with your variable being just NSArrays of ids. Source: WWDC '15 "Swift and Objective-C Interoperability" session See the transcript of the talk:...

AFNetworking file upload

ios,iphone,xcode

Some devices not recording sound correctly, but it is workng on simulator not working on real devices, check your code first then try again

Xcode Swift : Could not find member

ios,xcode,swift

You are using class PFLoginview instead of property logInView you can change to logo as below self.logInViewController.logInView.logo = logInLogoTitle ...

Swift error: Could not find an overload for '<' that accepts the supplied arguments

ios,xcode,swift

Try this : if count(password) < 5 { ... } ...

How to always show debug window in XCode6

xcode,xcode6

If Paul moves his comment to an answer I'll delete mine and upvote his. Here was a screenshot I was preparing when he got his comment in: You want the "show" issue navigator item checked to on....

When trying to include “ in a String, using \” works but the \ is included too

xcode,string,swift,string-formatting

As you can see in the documentation: String literals can include the following special characters: The escaped special characters \0 (null character), \ (backslash), \t (horizontal tab), \n (line feed), \r (carriage return), \" (double quote) and \' (single quote) (snip) let wiseWords = "\"Imagination is more important than knowledge\"...

Objective C - bold and change string text size for drawing text onto pdf

objective-c,xcode,pdf,size,bold

Solved it by making a separate method as below (I used + since I have this inside an NSObject and is a class method rather than in a UIViewController): +(void)addText:(NSString*)text withFrame:(CGRect)frame withFont:(UIFont*)font; { [text drawInRect:frame withFont:font]; } Outside the method, declaring inputs and calling it: UIFont *font = [UIFont fontWithName:@Helvetica-Bold"...

Chance of a conditional occurring in Swift: Xcode

xcode,swift,if-statement,conditional,percentage

You can use arc4random_uniform to create a read only computed property to generate a random number and return a boolean value based on its result. If the number generated it is equal to 1 it will return true, if it is equal to 0 it will return false. Combined with...

UIView within a container view not showing

ios,xcode,swift

All you have to do is Set the label ":" in centre vertical and horizontally and align all the constraints according to it . align the blue view giving it top , height , width and centre X to the label ":" and all other views giving them top and...

UIWebView path depends on previous pressed button Xcode

ios,objective-c,iphone,xcode,uiviewcontroller

in your ClassA.m - (IBAction)button1:(UIButton *)sender{ path=[[NSBundle mainBundle] pathForResource:@"filename" ofType:@"pdf"]; [self performSegueWithIdentifier:@"yourIdentifierName" sender:self]; } - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if([segue.identifier isEqualToString:@"yourIdentifierName"]) { classB *clsB =segue.destinationViewController; clsB.typeofSelect=path; } } in your class B.h @property (nonatomic, weak) NSString *typeofSelect; in your Class B.m @synthesize typeofSelect;...

SKEmitterNode particles lag at start

ios,xcode,swift,particles,skemitternode

The solution was setting the advanceSimulationTime to exactly 1.0 sec. I'm not entirely sure why this is the case, but I suppose that the creation "animation" takes up this time. Anyway, case closed and thanks for the help to everyone, especially lchamp since he suggested the solution....

Xcode + AWS Integration Apple Mach-O Linker Error

ios,xcode,amazon-web-services

Are you importing the AWS Mobile SDK for iOS using both the frameworks and CocoaPods? You cannot import the SDK twice, and that is why you are getting duplicate symbols errors. You need to pick one of them and remove the other one to remove the errors.

type casting in objective-c, (NSInteger) VS. integerValue

ios,xcode,casting

NSNumber is a class; NSInteger is just a typedef of long, which is a primitive type. dic[@"count"] is a pointer, which means that dic[@"count"] holds an address that points to the NSNumber instance. NSNumber has a method called integerValue which returns an NSInteger as the underlying value that the NSNumber...

Why label still append 0 once press clear button “C”?

xcode,swift

Just add this condition into displayHistory() method : if history.text == "0" { history.text = historyLabel }else { history.text = historyLabel + history.text! } ...

Filter array based on coordinate from mapview frame in objective C

ios,objective-c,xcode,annotations,mkmapview

What you could do is: A) get the annotations directly: MKMapRect visibleMapRect = mapView.visibleMapRect; NSSet *visibleAnnotations = [mapView annotationsInMapRect:visibleMapRect]; B) Loop through your array and check whether the point is inside: MKMapRect mapRect = mapView.visibleMapRect; for (NSDictionary *item in array) { CLLocation *location = item[@"location"]; // Or what ever you...

Xcode - Colours look different but should be the same

ios,xcode,hex,uicolor

Because of the blurring effect on a translucent UINavigationBar, the color you set is not exactly how it will be displayed on screen. You can either set your navigation bar's translucent property to NO: self.navigationController.navigationBar.translucent = NO; ... or use this handy calculator to work out the correct input color...

UITapGestureRecognizer sender is the gesture, not the ui object

ios,xcode,swift,uigesturerecognizer

You can get a reference to the view the gesture is added to via its view property. In this case you are adding it to the button so the view property would return you you the button. let button = sender.view as? UIButton ...

Running app from console gets CodeSign error: code signing is required for product type 'Application' in SDK 'iOS 8.1'

xcode,xctool

After reading several posts at stackoverflow and several post at Github, I found this one where I found a solution at the end. Therefore, my solution was: xctool/xctool.sh -workspace Supermaxi.xcworkspace -scheme Supermaxi build CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO It worked for me....

Can't figure out coder aDecoder: NSCoder

ios,xcode,swift

Your custom initializer cannot initialize the immutable property. If you want it to be immutable then, instead of creating a custom initializer, just initialize in one of the required or designated initializer. Like this, class AddBook: UIViewController { @IBOutlet weak var bookAuthor: UITextField! @IBOutlet weak var bookTitle: UITextField! let bookStore:...

UISearchController shows incorrect results

ios,xcode,swift,core-data,uisearchcontroller

I found a solve, I changed my UITableViewController class FirstTableViewController: UITableViewController, NSFetchedResultsControllerDelegate, UITableViewDataSource, UITableViewDelegate, UISearchControllerDelegate, UISearchResultsUpdating, UISearchBarDelegate { @IBAction func addNew(sender: UIBarButtonItem) { } let managedObjectContext: NSManagedObjectContext? = (UIApplication.sharedApplication().delegate as? AppDelegate)?.managedObjectContext var fetchedResultsController: NSFetchedResultsController? // MARK: - setting for search...

iOS : pod update (unable to find the utility “xcode-select”)

ios,xcode,osx,xcode6,cocoapods

First of all check you have to install command line or not. You can check this by opening Xcode, navigating the menu to Xcode > Preferences > Downloads > Components, finding Command Line Tools and select install/update. if you haven't find command line tool then you need to write this...