Changes made to UI objects are not updating in iPhone simulator - iphone

I'm new to objective-c and iPhone, but have done lots of java coding in past.
Tearing hair out about v. basic things which I'm usually eventually able to find answer to, but not this one!
I'm wanting to make a label's background colour change, code below. No matter what I do it doesn't change when I run it on the iPhone simulator. Is there some setting there, I feel like I'm asking a very stupid question but really can't find an answer. Is this a problem with the setup of the development environment??
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSLog(#"setting label to black color");
self.colourLabel.backgroundColor = [UIColor blackColor];
}

Why don't you make an IBOutlet of type UILabel, hook it up to the label in the interface builder and do:
yourLabel.backgroundColor = [UIColor whateverColor];
Did you set colorLabel as a property? Because you wouldn't need to... unless you have two separate classes that you want to communicate with each other.

Remember that in Objective-C sending messages to nil objects is fine, so the problem may be that self.coulourLabel is still nil at that time.
How and where do you instantiate it? Did you set the IBOutlet?

Just thought I'd leave an answer emphasising the suggestion from #Dima in the comments on the question - ie, Project > Clean and then iOS Simulator > Reset Content And Settings.
I just solved a similar problem which was occurring with a UIButton created in code, and so couldn't have been an IBOutlet issue. Changes I made to the code (even deleting the property altogether) weren't showing up when I ran in the simulator, even though on my device it worked fine. I had assumed that doing a clean would be enough but it wasn't until I did the Reset Content And Settings that it started behaving as I expected.
Hope someone finds this useful...

Related

Difference between view.hidden = x and [view setHidden:x]

I'm debugging an iphone app and I'm seeing something I don't understand fully.
Based on user's selection, a UIView is being shown or hidden. Current code shows or hides the view with [view setHidden:NO] and [view setHidden:YES]. This doesn't work: visually it's as if these statements are simply ignored. However when I changed these to view.hidden = NO and view.hidden = YES respectively, everything is working as expected.
I was thinking that the two syntaxes are equivalent, but apparently not. For all other attributes (text, font, etc.), both work identically, so what's so special about hidden?
EDIT: Here's the copy/paste of some of my code. I'm working in XCode 4.3 with iPhone simulator 5.0
Here's one example from my project.
IBOutlet UIView *panel; //Connected in interface builder
===========
- (void)makePanelVisible:(BOOL)visible
{
[panel setHidden:!visible]; //this does not work
panel.hidden = !visible; //this does work correctly.
}
Sets whether the view is hidden.
- (void)setHidden:(BOOL)flag
Returns whether the receiver is marked as hidden.
- (BOOL)isHidden
hidden=YES; is identical to setHidden:YES; The difference is, you are turning hidden to YES right away Whereas sethidden view disappears from its window and does not receive input events because it is set to be hidden. It remains in its superview’s list of subviews, however, and participates in autoresizing as usual.
Thinking back about this, I remember running into the same issue almost 3 years ago, when iPhone 3 (not even 3G) was all the rage. I'm not sure why this happens, but it does - so I just deal with it by setting the property using the "dot" notation. I guess, this is one of those "don't fix it if it ain't broken" things (ok, it is sort of broken, but there's an easy way around it, so I'm using it).
hidden is a property of UIView. When you wrote [panel setHidden:YES], you try to call the method setHidden that should set the property hidden. It doesn't work because the method doesn't exist in the UIView : https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/doc/uid/TP40006816
I always set the property by writing "view.hidden = x".
I hope it will help you

Cocoa Touch UITextView setText: method useless

I have a UITextView which I create in Interface Builder for an iOS app. I checked (and double checked, and triple checked) that it is properly connected to the outlet in my code. I create a property and synthesize it, and when I run NSLog(#"%#", myTextView);, it returns the UITextView's properties, not null. However, when I try calling [myTextView setText:#"My Text."];, it doesn't change anything on the view. I have found many people with similar problems like this on Stackoverflow and other places on the internet, however none of the solutions there helped me. I am using Xcode 4.0.2 on Snow Leopard. I am attempting to do this in the -viewDidLoad method. What could be causing this issue?
If you need any more information about my code setup, post a comment and I will update this post.
Are you sure the whole text view is visible on screen, and that the font color is not the same as your background?
It is very likely that the view that is displayed on the screen is not the same view as myTextView points to. Check [myTextView superview] and make sure it's onscreen. Then look and see if you've accidentally covered it with something. Change other aspects like the backgroundColor. Also, check the frame and make sure it's not CGRectZero.

iOS - status bar randomly turns solid black

Developing an iPhone app.
I've got a really strange problem where, every once in a while, the status bar at the top of my app screen will turn solid black. Not like the black version of the status bar, but like a solid black rectangle with NO text/icons. It's very rare, but usually seems to occur after returning to the app via multi-tasking or from a locked device (the app has been running in the background). I've seen it occur on both 3GS and iPhone4. Here's a screenshot:
I can never reproduce it when trying, it just seems to eventually happen at some point (sometimes it will go for days without happening).
Once it does occur, the app seems to continue functioning fine, even with the status bar gone, except for when I do one specific action in the app which will cause everything to freeze up all the sudden (the app doesn't crash, but everything on screen is frozen and non-interactive). Without explaining the design in detail, the specific action that causes it to freeze up (after the bug appears) is performing a simple upload in the background to a SQL database. Resetting the app is the only way to fix the problem once the black status bar appears.
Anyone else ever experienced this? I can't find a single thread anywhere explaining similar behavior, and it's driving me nuts.
It happened once in my app when I called a drawing method in my custom subclass of UIView instance right before I added it as a subview to parent view.
The solution was apparently easy: add it as a subview first before sending/calling any custom drawing methods.
Examples:
CustomView *aView = [[CustomView alloc] init];
[aView drawSomething];
[self.view addSubview:aView]; //wrong approach
[aView release];
Should be:
CustomView *aView = [[CustomView alloc] init];
[self.view addSubview:aView];
[aView release];
[aView drawSomething];
The screenshot is missing, but what you describe sounds as though you've incorrectly implemented the use of Apple's built-in view controllers.
Both UINavigationController and UITabBarController will automagically shift all the content inside them down by 20-pixels, if they detect there is "supposed" to be a statusbar on screen at the moment.
My guess is that you have some code that is removing the statusbar, but which is kicking-in after the Apple code has already detected it and shifted everything down to accomodate.
The "fix" is to re-read the docs on Apple's classes very carefully and use them as Apple dictates (usually, people use them in ways that seem sensible - e.g. embedding them inside other views - but which Apple has expressly declared are unsupported. Sadly those classes from Apple are very fragile)
Are you holding a reference to a QLPreviewController instance? I was able to solve this problem in my app by creating a new autoreleased QLPreviewController whenever I need to display a file modally, as opposed to reusing the same instance over and over again.
I had a similar problem, which I described in this question here
If you have any, try removing any CGRect frame created by reference to:
[UIScreen mainScreen].applicationFrame]
and instead create the frame using a more manual definition. If that works, you can decide how to proceed from that point.

UITabBarController, UINavigationController and autorotate

i have problem with autorotate on iphone
i set up in all classes
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
but it is not respond ;/
Sample code is: http://b6.s3.p.quickshareit.com/files/testautorotatecb367.zip
problem is only with first tab, if i switch application to second tab, and rotate iphone, interface is rotating. it is not rotating in TAB1, where i put custom UINavigationController
OK
problem is that i do not init navigation views, i use only alloc, after i add alloc] init] all started works OK
Okay, i think i see what the problem is in you code. You need to add your UINavigationBar to the delegate like you did with the tab bar, otherwise it doesn't know of its existence and therefore it isn't rotating because it is confused on what is in the view.
Because I use Interface Builder to take care of all my GUI needs, i'm not sure how to do this manually in code, so, to help you out, here >> http://www.radford.edu/ebalci/Tutorials/SimpleTabNavTemplate.zip is a tutorial kind of thing i made a few days ago for a friend, you can use it as sort of a template or guide to help you out (i hope it will help you)
[my tutorial uses UItableViews for navigation but that is optional]
also, i commented out my rotation methods because i wasn't worried about it at the time, but
if you uncomment them (and i think you have to add the method to one of the classes because i deleted it) it will rotate, i just checked, but was too lazy to re zip it and upload it.
I just want you to know that I pretty much just made this thing a day ago, there is a rich text file in the zip that has instructions, but, it is a rough draft, i haven't really revised it yet so, i hope you can read through it with ease despite the fact it is a rough draft.
Let me know if it helps =) Good Luck
And your custom UINavigationController also has the same
shouldAutorotateToInterfaceOrientation
method that returns YES to landscape views?

UIViewController not responding to touches

Hey all, I'm completely stumped with this iPhone problem.
This is my first time building a view programmatically, without a nib. I can get the view displaying things just fine, but the darn ViewController isn't responding to touches the way it used to in programs where I used a nib. I should add that in the past, I started with the View-Based Application template, and this time I used the Window-Based Application template.
My thinking is that the View-Based template does something magical to let the iPhone know where to send the touch events, but I can't figure out what that would be even after several hours of bumbling around Google. Or I could be looking in an entirely wrong place and my troubles are related to something else entirely. Any thoughts?
There's nothing magical in the view-based template. The most likely reasons for failure to respond to touches are:
You've messed with touchesBegan:withEvent:, userInteractionEnabled, exclusiveTouch or something else, thinking you need to mess with these (generally you don't; the defaults are generally correct)
You created a second UIWindow
You put something over the view (even if it's transparent)
Simplify your code down to just creating a view programatically that responds to a touch and nothing else. It should be just a few lines of code. If you can't get that working, post the code and we'll look at what's going on.
Problem solved. touchesEnded != touchedEnded.
That'll teach me to program without my glasses on.
Another possible scenario for failure in response to touches is when your VC frame is not predefined and its boundaries are actually exceeding the window placeholder. It happens a lot when you just forget to define the frame property for the VC.
Once you define it correctly - User interaction returns to normal.
Good luck !