icarousel not displaying items - objective-c

I've been working with iCarousel for about a week now, and I've had great success with outside testing. Now, I'm trying to put it into my app and it won't display the views. I was using UIViews to be displayed originally, which was working fine in my test programs, but due to sheer frustration im going as basic as possible and have literally just copied everythinng over from the examples. I connected the delegate and datasource, I called reloadData, ive done everything i could possibly find to fix this and it's not getting fixed. here's some code implementing the actual icarousel:
- (IBAction)coverflowPressed:(id)sender {
self.carousel = [[iCarouselExampleViewController alloc]
initWithNibName:#"iCarouselExampleViewController" bundle:nil];
[self presentViewController:self.carousel animated:YES completion:nil];
}
The rest of the code is basically copied from an example that works outside my app. As i mentioned, i DID connect the delegate and dataSource. It displays the background just fine, but it's like the carousel is empty; it has no items in it, and yes, there ARE items in it. any ideas for me?
EDIT
Maybe i connected the delegate and datasource wrong. could somebody maybe explain how to do that from an app thats already halfway through production?
Breakpoints prove that it's never reaching carousel-specific functions, like viewForItemAtIndex or even awakeFromNib. viewDidLoad is called, so i set the delegate and datasource in there. Originally they were set in the nib but i changed it to programmatically. anyways heres my viewdidload method:
- (void)viewDidLoad {
[super viewDidLoad];
self.carousel.delegate = self;
self.carousel.dataSource = self;
//configure carousel
_carousel.type = iCarouselTypeCoverFlow2;
}
it reaches the end of this function but it never goes any farther with it...

Related

Reloading UICollectionView causing flickering

I have subclassed a CollectionView and using it using to display a collection of images in different categories. For example: Most Popular, Most Viewed. I access each category/page through a TabbarController.
The classes I have are:
Main class - MediaList - Base class for fetching and displaying media in a collection view depending on what type of media is requested.
SubClasses - MostPopular and MostViewed are both very light classes that inherit from the main class.
The problem is that when I move from MostPopular to MostViewed, the collection view initially displays the last category of pictures and then refreshes to the new...As a result you see a flicking effect.
Sample code from MediaList
- (void)viewDidLoad
{
[super viewDidLoad];
self.mediaCollection.dataSource = self;
self.mediaCollection.delegate = self;
[self getMedia];
}
(void) getMedia
{
NSLog(#"///////////////////////// GETTING MEDIA /////////////////////////");
XMLGenerator * sharedXmlGen = [XMLGenerator sharedXmlGenerator];
GlobalVars * sharedGlobalVars = [GlobalVars sharedGlobalVars];
sharedXmlGen.assetFlag = _contentFilter;
NSLog(#"The filter is: %#", _contentFilter);
[sharedXmlGen getPhotoVideoWithCallBackFunction:^{
[_mediaCollection performSelectorOnMainThread:#selector(reloadData) withObject:nil waitUntilDone:YES];
}];
}
Sample code from SubClass (MostPopular):
- (void)viewDidLoad
{
[super setContentFilter:FILTER_POPULAR]; //Set the filter for the type of content
[super viewDidLoad];
// Do any additional setup after loading the view.
}
Two clarifications:
I should add that I am trying to re-use as much code as possible without having to create new views on the storyboard or controllers.
Because the media returned is very dynamic and can be updated regularly, I have had to reload my data (using getMedia) on viewDidAppear. This now means each selection of a particular page will result in the flickering when the new view is loaded...
Updates
- After further investigation it looks like this has nothing to do with subclassing the uicollectionview. The issue instead is just reloading data into the uicollectionview. To be sure, I just clicked on one of the two subclassed views. I also added a reload method to the viewdidAppear method just to see the issue get even worse. It's also much easier to see that the issue is that last set of images in the collection view initially displays the last category of pictures before the new one refreshes. Then once the collection is refreshed I get the flicker.
*Updates Oct 4 *
Starting to think my best solution is to display a waiting indicator and block the page while loading. I did try setting the uicollectionview to nil, and believe that will solve the problem as well, but not sure it will be straightforward to reset.
Although it may not be immediately apparent in the code above the root cause was actually the getMedia call. All of the subclassing etc. works perfectly fine.
Specifically having the reload method in the getMedia call and was creating the issue.
[_mediaCollection performSelectorOnMainThread:#selector(reloadData) withObject:nil waitUntilDone:YES];

Hiding the KeyWindow to cause a blank screenshot to be taken

I am trying to prevent the Apple implemmntation of taking a screenshot of the current screen contents when an app suspends into the background. I have found a piece of code that sort of works but it comes with a catch. What it does is that it clears the keywindow on the screen so when the snapshot is taken, it is of a blank screen. This is the code snippet for the functionality:
- (void)applicationWillResignActive:(UIApplication *)application
{
[ UIApplication sharedApplication ].keyWindow.hidden = YES;
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[ UIApplication sharedApplication ].keyWindow.hidden = YES;
}
The trouble with the above code is that when the app returns to the foreground, the view is gone as it has become hidden and i cannot unhide it with a simple
[ UIApplication sharedApplication ].keyWindow.hidden = NO;
in the applicationWillEnterForeground method of the app delegate. Does anyone know of a way to regain back the hidden view once i have hidden it in the background methods? Right now it is a black screen as the view has been hidden. What exactly happens when you hide a keywindow before going to background and then coming back. is that keywindow you hid before no longer the keywindow? Can anyone point me in the correct direction?
Thanks
Just made a demo project and was able to reproduce your issue. Indeed, the keyWindow property of the application is nil when applicationWillEnterForeground: is called.
Many times, your application's delegate will have a reference to its window - this is usually the Xcode default template for many applications. I was able to resolve the issue by calling
self.window.hidden = NO;
Instead of [UIApplication sharedApplication.keyWindow.hidden = NO;. Assuming that, like most of the templates, your application delegate has a window reference.
Another alternative that worked for me is to call [self.window makeKeyAndVisible];.
All this was done on the iOS 6 simulator.
Hope this helps!

Displaying UIViewController, NSOperationQueue

I have been on an iOS 5 app in which I have an NSOperationQueue which works fine to get some data and create a UIViewController. However, at one point when every operation seems to be complete the app is unresponsive for quite a long time. Here's how it goes:
Get some data from DB
Queue - For each item Init a custom UIViewController object.
Hand each UIViewController object over to the MainViewController and display them.
Everything goes fine until the UIVC objects have to appear.
It goes past all the [[self view] addSubview:object.view]; and to the end of the function.
But then there is a huge lag, from 5 to 30 seconds before the NSLog statements inside the viewDidApear of the UIVC object show up...
So in code:
//MainViewController
-(void)displayNewView {
[[self view] addSubview:object.view];
NSLog(#"Done setup");
}
//-- Long unresponsiveness --//
//UIVC object
-(void)viewDidAppear:(BOOL)animated {
NSLog(#"Start appear");
[super viewDidAppear:animated];
}
What could be causing this? Am I missing something obvious?
Thanks for the help!
It seems like it was the complexity of each UIViewController that delayed the whole process.
To me they seem simple but I guess the iPhone doesn't like creating 10 views at a time with several buttons, labels and images.
Simplifying the nib and making sure only what is used is allocated and initialized helped a lot.. but its still not perfectly fluid.

Stop UIPopover from dismissing automatically part II

Sorry I previously posted a question here, but The answers I got didn't work (probably my fault).
Basically, I want to stop a UIPopover from dismissing automatically. I got to this piece of code:
- (BOOL) popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
return NO;
}
which I put in, but it doesn't seem to have any effect. Is there anything else I should add?
am I putting it in the right place (I was putting it in the vc.m of the view that has the popover within it)?
Thanks Very Much,
Luke
Check to make sure the UIPopover delegate is set. You can do this in code by setting the popover instance variable:
aPopover.delegate = self;

Why strange crash with mapview happen?

I have a very simple app. 1 navigationController with 2 viewControllers.
The first view has only a button.
The second view has a map view (MKMapView).
I checked show currentlocation property of this map view
I created outlet and then connect everything by using Builder Interface.
In the dealloc method of the second one, I set nil to delegate of mapview, and then release mapview outlet.
mapView.delegate = nil;
[mapview release];
When I tap the button in view1, view2 will be loaded, and then I tap back button. If I do it normally, everything works well. But If I do it very quickly, repeat many times. The app will be crashed.
If I do not release mapView or I do not check showcurrentlocation property, app works well.
I can't figure out why this happen. Anyone helps me solve this problem. Thanks so much !
My fix in controller class was to ..
(void)dealloc
{
mapView.showUserLocation = NO; // Work around bug in MKMapView
[super dealloc];
}
Try launching your app via Instruments with Zombie instrument added. It should show you overreleased object. You'd also should add the Allocations instrument with VM tracker to see how memory consumption goes over time. This way you'd get your answer very quick.
p.s. more code would help better.