I've got a UIProgressView in my Storyboard hooked up to my code. I'm trying to set the progress to something non-zero.
Here's an example of my code that I've placed in viewDidLoad.
[self.progressBar setProgress:(float)someValueBetween0.1and1.0 animated:NO];
However, what's happening is that the progress bar will be at the value that I set, and then quickly animate down to 0.0. For instance, if I set progress to 0.5, the bar will be filled half way when the view loads and then animate down to 0.0.
I've tried using
self.progressBar.progress = (float)someValueBetween0.1and1.0;
That hasn't worked either.
I'm not modifying the progress bar's progress via code anywhere else. I've tried Googling, reading the UIProgressView Class Reference, and searching Stack Overflow without any success :/
Edit: Created a new project with nothing more than a UIProgressView just to be sure it's not something else in my code. Still not working.
#import "ViewController.h"
#interface ViewController ()
#property (weak, nonatomic) IBOutlet UIProgressView *testProgressView;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.testProgressView setProgress:1.0 animated:NO];
}
This is a bug in Xcode Version 7.0 beta (7A120f).
I've confirmed it in both Objective C and Swift.
It only occurs in the beta version, the same source executes correctly in Xcode 6.
Very strange bug.
Related
I am trying to add a SKScene with a simple animation to a UICollectionCell.
I've got my SKView setup in the .xib file of the collection view cell.
If I run it and scroll, it works as expected. But if I change to a different view controller (in a tab bar controller) that also uses those types of cells and start scrolling, it will get stuck.
Here's how I am adding the SKScene:
#interface MAPostCollectionViewCell ()
#property (strong, nonatomic) IBOutlet SKView *viewAnimation;
#property (strong, nonatomic) MAHeartAnimation *heartScene;
#end
#implementation MAPostCollectionViewCell
-(void)layoutSubviews{
[super layoutSubviews];
self.heartScene = [MAHeartAnimation sceneWithSize:self.viewAnimation.bounds.size];
self.heartScene.scaleMode = SKSceneScaleModeAspectFill;
[self.viewAnimation presentScene:self.heartScene];
}
#end
And I only trigger the animation if the user taps a button.
But for the scope of this question, the animation doesn't really matter, as I am not touching that button, just scrolling the UICollectionView.
It turns out you should not use SpriteKit and UIKit this way. Even though they are modular frameworks, they are not performant when using together this way. I ended up using UIKit for the animations that I wanted, by using CALayers.
Currently I have a BOOL in runtime attributes for my view controller that I use to see if my view controller should add a button to the navigation bar programmatically. I was told that to access the attribute in the code, you add a property with the same name like this:
#interface MyViewController
#property (nonatomic, assign) BOOL showButton;
#end
#implementation
#synthesize showButton = _showButton;
-(void)viewDidLoad {
[super viewDidLoad];
if (_showButton) {
//show button
}
}
#end
And this does work in iOS 8 and 9, but for some reason in the simulator, iOS 7 does not read the Boolean and it's always set to false.
I feel like this is a serious enough problem that someone should have an answer but Google or the search results on SO didn't seem to have results for this.
I really appreciate the help!
UPDATE: I set the value in the Storyboard.
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 have a randomly generated int that I assign to a tag for a UIImageView on my storyboard in ViewWillAppear.
When I segue to the main menu and try to enter the view again, however, the app crashes. I know it's because of the tag because when I remove it everything works fine.
Any thoughts on why it works the first time but not on times after that? Code below.
ViewController.h:
#interface ViewController : UIViewController{
int tagnumber;
IBOutlet UIImageView *box;
...
}
ViewController.m:
-(void)viewWillAppear:(BOOL)animated{
tagnumber = arc4random()%1000;
box.tag = tagnumber;
...
}
- (IBAction)unwindToThisViewController:(UIStoryboardSegue *)unwindSegue
{
[_animator removeAllBehaviors];
[box removeFromSuperview];
}
MainMenu.m:
-(IBAction)prepareForUnwind:(UIStoryboardSegue *)segue {
}
Basically, when the view disappears and the system is running out of memory, it will call on UIViewController's implementation of didReceiveMemoryWarning. There is a fantastic description of this here: ViewWillDisappear versus dealloc
When you are creating an IBOutput you should really have a weak pointer to it by saying #property (weak, nonatomic) IBOutlet UIImageView *box. Views retain their subviews, and therefore, if a view gets deallocated, its subviews retain count decreases by one. When the view disappears, the system will decide when to deallocate self.view, and when it does, it will automatically release box, and box will get deallocated as well. You don't really need to worry about it.
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.