I am trying to write a hello world app on Xcode but I have two errors
The first error message is DTAssetProviderService could not start DTXConnection with Simulator 'iPhone 5'. Check the system log for errors. but I still can run the app but when I run the app on simulatior it does not show the button and label I put in the app. It shows just a screen of the app. Here is my codes in the app for ViewController.h and ViewController.m
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController {
IBOutlet UILabel *hellolabel;
}
- (IBAction)button1:(id)sender;
#end
ViewController.m
#import "ViewController.h"
#implementation ViewController
-(IBAction)button1:(id)sender {
hellolabel.text = #"hello world";
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[ super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
And here is my main.storyboard interface
enter image description here
put your button and label in top - left side in your storyboard interface builder for now and you can see it on simulator.
It is because of different screen sizes, size classes and autolayout.
You should learn autolayout, after you can set constraints to your components and this kind of problem will not be faced.
The issue is probably in your main.storyboard, which you haven't linked below. More than likely, as others have said, you've mucked up your constraints.
On your main.storyboard delete any constraints and move all your buttons to the left most side. Also make sure that your width and height read wAny hAny, as that is the best to use for any screen.
Related
I added iAd to my application using self.canDisplayBannerAds. The application uses UITabBarController and that seems to be causing a problem. See the "empty" (gray) space in the screenshot below.
The UITextView has the following constraints:
And the program is very simple:
#import <iAd/iAd.h>
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.canDisplayBannerAds = YES;
}
#end
This simple program, with the canDisplayBannerAds commented out (or set to NO) doesn't have a gray rectangle at all. But with ads I can't seem to get rid of that "empty" (gray) rectangle. Does anyone have a suggestion to resolve this issue?
Demo project on github.
Just make your ViewController's TabBar to Opaque and your problem will be resolved.
I’m trying to make a scroll view in xcode. I used the following code in xcode 5 (which worked):
view.h:
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController {
IBOutlet UIScrollView *ScrollView;
}
#end
view.m
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[ScrollView setScrollEnabled:YES];
[ScrollView setContentSize:CGSizeMake(320, 1005)];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
I have seen others with this problem but none of their solutions worked for me. Note that i have size set to freedom and auto layout is turned off.
Try this - UIScrollView with Autolayout
OR
try setting your content size in viewDidAppear
Due to a scrollView feature in auto layout, the contentSize is being redefined. To solve this problem, you could disable auto layout or set the content size in viewDidLayoutSubviews()
-(void)viewWillLayoutSubviews {
[super viewDidLayoutSubviews];
ScrollView.contentSize = CGSizeMake(320,1005);
}
So you would want to add this code and delete the ScrollView.contentSize method in viewDidLoad.
I don't see anything immediately wrong with this code. I would check and makes sure that you've connected the IBOutlet properly in the Interface Builder.
I'm working on an old project of mine with a xib file in it. I have a button that changes the position of an UIImageview to 0,0, but it doesn't work and the label stays at its initial position. When I create new project with the exact same code expect it contains a mainStoryboard.Storyboard it works fine. I suppose it has something to do with the xib file and files owner.
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)Action1:(id)sender {
imageview.center = CGPointMake(0, 0);
}
If you're using auto layout, changing the frame may not have any effect.
Instead, you need to change the constraints on the view.
You can find a written tutorial on auto layout on Ray Wenderlich's site here or a video tutorial here.
I'm quite new at iOS development and I'm facing some trouble with hiding/showing button in my GUI. Because I need some buttons to appear or disappear and to be enabled or disabled. I followed some great tutorials over the net but can not figure out what is going wrong with my code.
Here is my ViewController.h :
/
// ViewController.h
// WeddingVideoBooth
//
// Created by Frédéric Mouza on 15/07/13.
// Copyright (c) 2013 Frédéric Mouza. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController{
IBOutlet UIButton *but_record;
}
#property (nonatomic,retain) IBOutlet UIButton *but_record;
- (IBAction)but_record:(UIButton *)sender;
#end
and my .m file :
//
// ViewController.m
// WeddingVideoBooth
//
// Created by Frédéric Mouza on 15/07/13.
// Copyright (c) 2013 Frédéric Mouza. All rights reserved.
//
#import "ViewController.h"
#import "MobileCoreServices/UTCoreTypes.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize but_record;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
but_record.hidden=YES;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)but_record:(UIButton *)sender {
but_record.enabled=NO;
}
#end
It's very simple and, to understand, I just would like the button to disable when you click on it... Currently, the button remains the same when you click on it. I also tried to hide it using the property "but_record.hidden=YES" but nothing worked.
Does somebody have an idea, please ?
Thanks again
Add an NSLog() into your but_record to see if the IBAction is actually getting called. It sounds like that is not triggering as you probably didn't link them together in your Interface Builder. And as mentioned above take out the hidden=YES
Ok, just to wrap-up and properly close the question.
It's probably obvious for most of you but when dealing with interface one has to be careful:
if you create a button, link it to the interface, give it properties... and then you copy it Xcode keeps the previous link in the copy and if you create a new link by control+drag in your .h file, the previous link remains and may supersede the new one.
Therefore, to prevent this, you have to remove the existing links from the link tab after you copied a button but before you create a new link.
That worked for me.
Hope this will help,
Fred
I am using XCode 4.6.1 and developing for iOS 6.
I have added a button to the storyboard. I have created an outlet in my implementation file ViewController.m:
//
// ViewController.m
//
#import "ViewController.h"
#interface ViewController ()
#property (weak, nonatomic) IBOutlet UIButton *b1;
#end
I try to change the button b1's properties as follows (in this same file: ViewController.m):
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.b1.alpha = 0.5;
self.b1.frame = CGRectMake(0,0,123,412);
}
When I run the app in the simulator, the alpha of the button is successfully set to 0.5.
However, the position and size of the button doesn't change.
I have tried various ways to make it happen. However nothing seems to work. I would like to know what am I doing wrong. I am pretty new to Objective C. Any help would be greatly appreciated.
You are probably using autolayout:
When using autolayout you cannot manually change your outlets frames. You have two options: you can either disable autolayout (then your code should work), or create outlets to your constraints and then modify the constrains programmatically:
#property (weak, nonatomic) IBOutlet NSLayoutConstraint *widthConstraint;
and then in your code:
self.widthConstraint.constant = 123;
and so on with all the constraints that need to be modified.