UIImageView's image not getting changed on postnotification in iPhone - iphone

In my app I have a UIImageView and at runtime once I download the image I am changing the image through postnotification but the image was not getting changed and I checked all my connections in nib and everywhere and it looks fine for me but still the image was not getting displayed can anyone help me in this regard. And my uiimageview was inside a scrollview and the scrollview was inside my main view
the following method was called on postnotification
- (void) refreshimages:(NSNotification *)notofication {
if ([[notofication name] isEqualToString:#"DownloadImgBinary"]) {
[activityview stopAnimating];
[activityview removeFromSuperview];
[self.view bringSubviewToFront:scrollView];
[self.scrollView bringSubviewToFront:imgCamera];
self.imgCamera.image = td.imgPhoto;
}
}

You need to check two things.
First, make sure that you are actually receiving the notification.
Put a breakpoint in the observer's target method, or stick an NSLog in there. If, when you do this, you see neither of them, then your notification isn't getting received.
Second, make sure that the image is actually getting downloaded.
Either use a web debugging proxy (I use Charles but it costs a bit, there are alternatives), or again, breakpoint somewhere. Or stick in a manual button somewhere that on-press tries to set the UIImageView's image, run the app, and press the button after you're sure the image downloaded.
Finally, to make sure something fishy isn't going on, stick two images in your project, give the imageView a default image (something glaringly obvious like checkerboard pattern), and then in the notification (assuming it is firing), set it to something else that is also glaringly obvious. Then test. This way you know that the bring-subview-to-front is working, and that your IB links are working.

Related

Activity Indicator Doesn't Stop/Start Properly

EDIT: Problem Solved!
For others, To fix it, simply right click the WebView, click the "delegate" circle, and drag it to "File's Owner" on the left side.
Thanks for the help
--I'm fairly new to app developing, I'm in my first semester actually. Since it's a brand new course, the instructor knows very little as well. Therefore I have complete permission to ask for help on this. Thanks!
On to my question...
I want to include an activity indicator in my app as my WebView starts and stops loading, simply enough. At this point, it will animate. However, my problem is that it starts before the WebView starts loading anything, and also doesn't ever stop. My current code is this:
- (void)webViewDidStartLoad:(UIWebView *)webView {
[activity startAnimating];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[activity stopAnimating];
Other than that, I have it set up in the header...
IBOutlet UIActivityIndicatorView *activity;
And as far as I can tell, set up rather properly. Oh, also, I do have "Animated" checked and "Hide When Stopped" checked in the .xib file.
UPDATE: NSLogs and breakpoints show that the methods aren't being called.
I am a highly visual learner, so, I will need to see what I am missing, unless it is a problem in the interface. Thanks...
Any help is much appreciated
Do you have your webView correctly connected to the delegate? Toss in an NSLog or a couple breakpoints and make sure that your functions are being called.
You can put a break point in your code to see if the webViewDidFinishLoading is called. I'm guessing it is not being called. There is another delegate methods you should implement (see UIWebViewDelegate Protocol Reference), called webView:didFailLoadWithError:. Implement that and put a break point inside it. Let us know what happens.
Did you see the apple developer examples?
Apple Developer Example Webview

UISegmentedControl Problem setting hidden

Hi I regulary created using IB one UISegmentedControl that I called showAllSwitch.
If I try to do [showAllSwitch setHidden:YES]; nothing happens!
Why? How can I do to hide it?
Where are you calling setHidden? if it is being called before it is added to the view, then there could be problems. Try calling it in viewDidAppear and see it that works. If it doesn't either the segmentedControl is not connected correctly in IB, or there is a rather big problem that we are missing.
Hiding an object is relatively straight forward. So if there is a problem then its something simple. You need to just go through some basic diagnostic steps:
Verify that your segmented control is actually connected to the correct outlet in IB. Really. Go look. Even if you are sure. Go look again.
Verify that the line where you are hiding it is being called. Add an NSLog just after and see if it shows up when it should.
Make sure that the hide command is not getting sent too soon. If its being sent in ViewDidLoad try setting it up in ViewDidAppear.

passing imageview through delegate

My programe does drag and move a little imageview by touch. When the location is decided, press a button to pass imageview to its superclass.
-(void) sendPosition:(CGPoint)position ;
when I run program for first, it runs ok but after I rerun the same process right after that, it occurs error.
Uhm..
-(void) sendPosition:(CGPoint) position withImageView:(UIImageView*) imageView;
maybe? (Sorry if this sounds stupid but I'm not sure if I understand your question correctly)

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.

TTTableImageItem doesn't load the image until scroll

I'm using the three20 project for my iPhone app. I've narrowed my problem down and I'm now just trying to re-create the 'Web Images in Table' example that comes with the project. I've copied the code exactly as in the project, with the exception that I do not use the TTNavigator (which the example does) but I am adding my TTTableViewController manually to a tabBar.
The problem is as follows; the images in the table should load automatically from the web, like in the example. But they only load after I scroll the table up and down.
In the console it clearly says it is downloading the images, and you see the activity indicator spinning like forever.. And unless I scroll up and down once, the images will never appear.
Anyone? Thanks in advance.
P.S:
If I'm using this code in any random UIView, It also doesn't work (only shows a black square):
TTImageView* imageView = [[[TTImageView alloc] initWithFrame:CGRectMake(30, 30, 100, 100)] autorelease];
imageView.autoresizesToImage = YES;
imageView.URL = #"http://webpimp.nl/logo.png";
[self.view addSubview:imageView];
If I put this code in my AppDelegate (right onto the window), it does work .. strange?
POSSIBLE SOLUTION:
Although I stopped using TTImageView for this purpose, I do think I found out what the problem was; threading (hence accepting the answer of Deniz Mert Edincik). If I started the asynchronous download (because basically that is all the TTImageView is, an asynchronous download) from anywhere BUT the main thread, it would not start. If I started the download on the main thread, it would start immediately..
Sounds like a threading problem to me, are you creating TTImageView in the main runloop?
I find one interesting thing. When I use combination TTTableViewController, TTTableViewDataSource and TTModel I have same problem with loading TTImageView. My problem was, that my implementation of Model methods 'isLoading' and 'isLoaded' don't return proper values after initialization of model. That forces me to call reload on model manualy in 'viewDidAppear' method and that causes image loading problem. So I repair my 'isLoading' and 'isLoaded' methods to both return 'NO' after Model init, and everything is fine.
When an image finishes loading try sending a reloadData message to the table view. This forces the table to recalculate the size of the rows and redraw the table. Just be careful that you don't start downloading the image again in response to this message.
I've written something similar to this where an image view will load its own image from the web.
Im my experience, when the image had loaded successfully but was not shown in its view, it was a case that the cell needed to be told to redraw.
When you scroll the table view, the cells are set to redraw when the come onscreen, which is why they appear when you scroll.
When the image loads, tell the cell that it is sitting in to redraw by sending it the message setNeedsDisplay.
That way, when the image finishes downloading, the cell its sitting in (and only that cell) will redraw itself to show the new image.
It's possible that you might not need to redraw the entire cell and might be able to get away with simply redrawing the image view using the same method call. In my experience, my table cells view hierarchy was flattened, so I had to redraw the whole cell.
I don't have an answer for what you want to do, but I will say that this is considered a feature, and the expected behavior. You use TTImageView in UITableView when you want to do lazy loading of images. TTImageView will only load the images whose frames are visible on the screen. That way, the device uses its network resources to download images that the user has in front of them, rather than a bunch of images that the user isn't even trying to look at.
Consider having a long list that may contain a couple hundred thumbnail images (like a list of friends). I know from experience that if you kick off 100+ image requests on older devices, the memory usage will go through the roof, and your app will likely crash. TTImageView solves this problem.
This is a thread problem. You can load the images by including the line:
[TTURLRequestQueue mainQueue].suspended = NO;
in - (void)didLoadModel:(BOOL)firstTime.