selected image wouldn't load in ego image viewer in ios 7 - iphone

I am using EGOPhotoViewer to load up a bunch of images from the s3. They are shown in thumbnails first in table view, so when a user clicks 5th row of image, it loaded the image into image viewer starting at 5 of 20 . and this is working smoothly in ios 6.
but when I installed ios 7 and run my app.I got an error. it fails to load the clicked image.
when user click 5th row of image,image viewer load the very 1st image starting at 1 of 20.
i am using this much of code.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{ ......
[self showSelectedPhoto:indexPath];
......
}
//load the selected image
-(void)showSelectedPhoto:(NSIndexPath *)indexPath
{
[UserInfo sharedInfo].Path=indexPath;
NSLog(#"%#",indexPath);
NSString *passingImageName=[[self.tableDataSource objectAtIndex:indexPath.row]objectForKey:#"fileName"];
NSMutableArray *photoArray=[self getFilteredArray];
NSMutableArray *urlsArray=[[NSMutableArray alloc] init];
// [self.tableView reloadData];
for (NSString *string in photoArray) {
NSLog(#"String Values:%#",string);
NSURL *imageUrl=[self getEnlargedImageImageUrl:[self._prefix stringByAppendingString:string]];
NSLog(#"Passing url is:%#",imageUrl);
photo = [[EGOQuickPhoto alloc] initWithImageURL:imageUrl name:string];
[urlsArray addObject:photo];
}
self.source=[[EGOQuickPhotoSource alloc]initWithPhotos:urlsArray];
photoController = [[EGOPhotoViewController alloc] initWithPhotoSource:source];
[self.navigationController pushViewController:photoController animated:YES];
NSUInteger index = [photoArray indexOfObject:passingImageName];
NSLog(#"index = %lu",(unsigned long)index);
[photoController moveToPhotoAtIndex:index animated:NO];
}
so it is ios 7 ui bug or whatever?

I got the solution of this,And it working fine For my app in IOS 7.
In EGOphotoviewer
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
NSInteger _index = [self centerPhotoIndex];
if (_index >= [self.photoSource numberOfPhotos] || _index < 0) {
return;
}
//Change here for IOS7...add "&&_index>0" after _rotating
if (_pageIndex != _index && !_rotating && _index > 0) {
[self setBarsHidden:NO animated:YES];
_pageIndex = _index;
[self setViewState];
if (![scrollView isTracking]) {
[self layoutScrollViewSubviews];
}
}
}

In EGOphotoviewcontroller in viewwillappear method
if ([self.navigationController isToolbarHidden] && (!_popover || ([self.photoSource numberOfPhotos] > 1))) {
[self.navigationController setToolbarHidden:NO animated:YES];
}
After calling this method in ios7 _pageindex value getting zero,i don't know the actual reason for this, but i will give one idea.
just assign _pageindex value after this statement,like indexpath.row or may be tag value what youwant to assign,
Then the things are going good...
njoy...

Related

UIScrollVIew View

I'm using iCarousel as a slot machine, for those who doesn't know iCarousel it is a UIScrollview with (paged, scrolling views). So in my app, I scroll it, then when it stops it shows the Image(Result) for 3 seconds, then a button pop-ups, if you press the button, it will delete the View(Image Result) then Rotates again.
Here is my way of deleting my carousel view:
NSInteger CurrentImage = carousel.currentItemIndex;
[carousel removeItemAtIndex:CurrentImage animated:YES];
[images removeObjectAtIndex:CurrentImage];
But then when the carousel.numberOfItems has 1 item left, it doesnt scroll, instead its just stuck there.
So I made a way to make it scroll even it has only 1 Item(index) left.
I inserted it with the last index, so I tried this:
[self.carousel insertItemAtIndex:0 animated:NO];
(but doesnt work)
then I tried another:
int lastObject = [images objectAtIndex: ([images count]-1)]
[self.carousel insertItemAtIndex:lastObject animated:NO];
(still doesnt work)
and also this:
int count = [images count];
[images objectAtIndex:count - 1];
(still no luck)
Am I doing wrong? or What are other ways?
Or can I just duplicate the last View? Thanks for the help.
EDIT:
Methods
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
if ([images count] == 1 || [self.carousel numberOfItems] == 1)
return 2;
return [images count];
}
- (NSUInteger)numberOfVisibleItemsInCarousel:(iCarousel *)carousel
{
//limit the number of items views loaded concurrently (for performance reasons)
return 7;
}
- (UIView *)carousel:(iCarousel *)_carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
if (index >= [images count] || index >= [carousel numberOfItems]) {
index = 0;
}
NSDictionary *obj = [images objectAtIndex:index];
view = [[UIImageView alloc] initWithImage:[obj objectForKey:#"image"]];
view.tag = index;
return view;
}
- (NSUInteger)numberOfPlaceholdersInCarousel:(iCarousel *)carousel
{
//note: placeholder views are only displayed on some carousels if wrapping is disabled
return 0;
}
- (CGFloat)carouselItemWidth:(iCarousel *)carousel
{
//usually this should be slightly wider than the item views
return 400;
}
- (BOOL)carousel:(iCarousel *)carousel shouldSelectItemAtIndex:(NSInteger)index{
return 5;
}
- (BOOL)carouselShouldWrap:(iCarousel *)carousel
{
//wrap all carousels
return wrap;
}
Delete Method:
-(void) deleteItem{
//Removes the object chosen
if (carousel.numberOfItems >= 1)
{
NSInteger index = carousel.currentItemIndex;
[carousel removeItemAtIndex:index animated:YES];
//[images removeObjectAtIndex:index];
//[images replaceObjectAtIndex:index withObject:[NSNull null]];
}
}
What you could do is make
- (NSUInteger)numberOfItemsInCarousel:(iCarousel*)carousel;
return always a value >1 (eg. 2); then make sure that
- (UIView*)carousel:(iCarousel*)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView*)view;
always returns a correct view for the minimum number of elements you return from numberOfItemsInCarousel.
Eg.
- (NSUInteger)numberOfItemsInCarousel:(iCarousel*)carousel {
if (numberOfViews == 1)
return 2;
return numberOfViews;
}
- (UIView*)carousel:(iCarousel*)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView*)view {
if (index >= numberOfViews) {
index = 0;
}
NSDictionary *obj = [images objectAtIndex:index];
view = [[UIImageView alloc] initWithImage:[obj objectForKey:#"image"]];
view.tag = index;
return view;
}
You should also make sure that the last element is never deleted of add some guards in the code above to manage the case when no elements are left.

App crashes while using setContentViewController in iOS 5

I am making my app compatible to iOS 5 but the app crashes on the code where i have used setContentViewController.
Here is my code.
[[ChoicesViewController sharedChoices] setCurrentValue:[[(UIButton *)sender titleLabel] text]];
[self.choicesPopoverController setContentViewController:[ChoicesViewController sharedChoices]];
CGFloat popoverHeight = 44.0f * [[[ChoicesViewController sharedChoices] choices] count];
[self.choicesPopoverController setPopoverContentSize:CGSizeMake(380.0f, MIN(400.0f, popoverHeight))];
if ([self.choicesPopoverController isPopoverVisible]) {
[self.choicesPopoverController dismissPopoverAnimated:YES];
} else {
[self.choicesPopoverController presentPopoverFromRect:[(UIButton *)sender frame]
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
here is what shared choices returns:
static ChoicesViewController *_sharedChoices = nil;
+(id)sharedChoices
{
if (!_sharedChoices)
{
_sharedChoices = [[[self class] alloc] init];
}
return _sharedChoices;
}
//When i comment the below code , the app wont crash in iOS 5 but the UIPopover is not shown too. And if I uncomment it it will crash in iOS 5.
-(UIPopoverController *)choicesPopoverController
{
if (!choicesPopoverController)
{
choicesPopoverController = [[UIPopoverController alloc] initWithContentViewController:self];
}
return choicesPopoverController;
}
You say you set breakpoints and found this line was the problem :
[self.choicesPopoverController setContentViewController:[ChoicesViewController sharedChoices]];
but there's a few things going on there. Where does it crash if you change that line to
id controller = self.choicesPopoverController;
id shared = [ChoicesViewController sharedChoices];
[controller setContentViewController:shared];
?
Finally i found the solution :
instead of writing
[self.choicesPopoverController setContentViewController:[ChoicesViewController sharedChoices]];
i did
choicesPopoverController = [[UIPopoverController alloc] initWithContentViewController:[ChoicesViewController sharedChoices]];
and commented out the this code
/*
-(UIPopoverController *)choicesPopoverController
{
if (!choicesPopoverController)
{
choicesPopoverController = [[UIPopoverController alloc] initWithContentViewController:self];
}
return choicesPopoverController;
}
*/
Now it doesnt crash in iOS 5.

Paged UIScrollview with lazy delayed loading

I need help with the uiscrollview implementation with the following requirements:
1) pagingEnabled = true.
2) lazy pages loading.
3) pages are loading in the background. So i need at first run loading the page X, then get the notification that the page is fully loaded and only then allow the user to scroll to it.
4) ability to change the current page.
My first attempt was to override the scrollViewDidEndDeacelerating and scrollViewDidScroll, but I had troubles with stucking on half of pages (when you stop the scroll on the half of the page and then wait for new page to add to the scroll) and empty pages (when the user scrolled too fast).
My second attempt was to override the layoutSubviews method of the UIScrollView and do all calculations there. But it seems to be very sofisticated.
So, I'd love to find any examples of similar implementations.
Now I have the code like this:
I've implemented scrollViewWillBeginDragging and scrollViewDidEndDecelerating:
- (void)scrollViewWillBeginDragging:(UIScrollView *)aScrollView
{
isScrolling = YES;
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)aScrollView
{
isScrolling = NO;
// Here we load the page that was prepared when the user was scrolling
if (needDisplay > -1) {
//NSLog(#"Loading queued page %d", needDisplay);
[self loadScrollViewWithPage:needDisplay forceAddToSuperview:NO animated:YES];
needDisplay = -1;
}
// minLoadedPageIndex - index of the first loaded page.
int selectedIndex = MIN(floor((aScrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1 + minLoadedPageIndex, [photoItems count] - 1);
[self loadScrollViewWithPage:selectedIndex - 1 forceAddToSuperview:NO animated:YES];
[self loadScrollViewWithPage:selectedIndex forceAddToSuperview:NO animated:YES];
[self loadScrollViewWithPage:selectedIndex + 1 forceAddToSuperview:NO animated:YES];
}
In loadScrollViewWithPage I create the page view controller which loads the data from the server in the background. I don't add the view to the scrollview until it loads the data from the server.
- (void)loadScrollViewWithPage:(int)page forceAddToSuperview:(BOOL)value animated:(BOOL)animated
{
DetailController *controller = page >= viewControllers.count ? [NSNull null] :[viewControllers objectAtIndex:page];
if ((NSNull *)controller == [NSNull null])
{
controller = [[DetailController alloc] initWithNibName:#"DetailController" bundle:nil];
controller.delegate = self;
controller.view.hidden = NO; //this will call viewDidLoad.
if (page >= viewControllers.count) {
[viewControllers addObject:controller];
}
else {
[viewControllers replaceObjectAtIndex:page withObject:controller];
}
[controller release];
}
// add the controller's view to the scroll view
if (controller.view && controller.view.superview == nil && (controller.isLoadedOrFailed || value)) {
[self setNumberOfVisiblePages:visiblePagesCount+1];
if (page < selectedIndex) {
// We are adding the page to the left of the current page,
// so we need to adjust the content offset.
CGFloat offset = (int)scrollView.contentOffset.x % (int)scrollView.frame.size.width;
offset = scrollView.frame.size.width * (selectedIndex - minLoadedPageIndex) + offset;
[scrollView setContentOffset:CGPointMake(offset, 0.0) animated:animated];
}
CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * (page - minLoadedPageIndex);
frame.origin.y = 0;
controller.view.frame = frame;
[scrollView addSubview:controller.view];
[controller viewWillAppear:NO];
}
}
Also I have a detailControllerDidFinishDownload method which is called when data for the page view controller has been loaded.
- (void)detailControllerDidFinishDownload:(DetailController *)controller
{
... //here I calculate new minLoadedPageIndex value
// reset pages frames
if (minLoadedPageIndex < oldMinPage) {
for(int i=oldMinPage;i < [viewControllers count]; i++) {
DetailController *detailsController = [viewControllers objectAtIndex:i];
if ((NSNull *)detailsController != [NSNull null]) {
CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * (i - minLoadedPageIndex);
frame.origin.y = 0;
[detailsController.view setFrame:frame];
}
}
}
// load the page now or delay load until the scrolling will be finished
if (!isScrolling) {
[self loadScrollViewWithPage:[photoItems indexOfObject:controller.photoItem] forceAddToSuperview:NO animated:NO];
}
else {
needDisplay = [photoItems indexOfObject:controller.photoItem];
//NSLog(#"pageControlUsed is used!!! %d", [photoItems indexOfObject:controller.photoItem]);
}
}
The problem I have now is that sometimes the scroll stucks on the middle (or somewhere near to middle) of the pages and it won't go to the nearest page bounce until I slightly more it. My tests showed that this situation happens if I scroll out of content view frame (the scroll view have bounces on) and wait for the new page to load. In 1 of the 10 times the scroll stucks.
Thanks, Mikhail!
There are a lot of things you are requiring at the same time. I suggest you have a look at this example.
http://ykyuen.wordpress.com/2010/05/22/iphone-uiscrollview-with-paging-example/
It's a very good starting point.

Badge value on "More" tab

I am making an iOS app which has a tabBarController, with more than 5 tabs. Thus, first four are directly clickable and the rest come under MORE tab.
I want to show a badge on the MORE tab if there is any badge for the tabs that are hidden inside this MORE tab.
I know about how to do that from this question.
But the order of my tabs is configurable. Is there a way I can configure the MORE tab such it just puts the badgeValue if I set a value for a tab inside it?
I am thinking of this:
- (void)updateBadgeValue:(NSInteger)count {
int index = [self.tabBarController indexOfObject:self.tabBarItem];
if (index > 4) { //Inside MORE tab
[[[self.tabBarController moreTabBarController] tabBarItem] setBadgeValue:[NSString stringWithFormat:#"%d", count]];
}
//Also setting badge of self.tabbarItem so that it remains when it is brought to "hot tab items".
}
I am looking for a solution such that I dont have to do that for every tab. Also, if the tab order is changed by the user, the badgeValue should also update accordingly.
Thanks.
Try using this:
- (void)updateBadgeValue:(NSInteger)count {
int index = [self.tabBarController indexOfObject:self.tabBarItem];
if (index > 4) {
int moreTabCount = count + [[[[self.tabBarController moreTabBarController] tabBarItem] badgeValue] intValue];
[[[self.tabBarController moreTabBarController] tabBarItem] setBadgeValue:[NSString stringWithFormat:#"%d", moreTabCount]];
}
}
UPDATE: You can respond to configuration changes by using
- (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed
delegate method in your UITabBarController's delegate (it should be AppDelegate). Let's do it:
- (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed {
if(changed) {
int count = 0;
int i; for(i = 4; i < [viewControllers count]; i++)
count += [[[[viewControllers objectAtIndex:i] tabBarItem] badgeValue] intValue];
if(count > 0)
[[self.tabBarController moreTabBarController] tabBarItem] setBadgeValue:[NSString stringWithFormat:#"%d", count]];
}
}
I think that it will work.
Try using this
[[[[[self tabBarController] tabBar] items]
objectAtIndex:4] setBadgeValue:[NSString stringWithFormat:#"%d",yourBadgeValue];
Here ObjectAtIndex is for your Tab where 0 represents your first tab etc...
You can use for Swift 4:
let messagesCount: Int = 5
self.tabBarController?.moreNavigationController.tabBarItem.badgeValue = " \(messagesCount)"

Unable to assign images to an imageView from an Array, but can assign images to an imageView from a UIImage variable

I have a problem with arrays and passing images between views that I would like some help on!
So the background is that I have:
• RootViewController (which handles my table view)
• CommunicationViewController which handles the detail of the selected element from the table
• SelectSlideViewController which displays an image clicked on from the CommunicationViewController and allows the user to select a different one from the camera roll
So the problem:
• In the CommunicationViewConroller, I have the following code if the user clicks on a button:
- (IBAction) selectSlide:(id) sender
{
if(self.selectSlideView == nil)
{
SelectSlideViewController *viewController = [[SelectSlideViewController alloc]
initWithNibName:#"SelectSlideViewController" bundle:[NSBundle mainBundle]];
self.selectSlideView = viewController;
[viewController release];
}
[self.navigationController pushViewController:self.selectSlideView animated:YES];
self.selectSlideView.cmn = cmn;
self.selectSlideView.title = cmn.name;
self.selectSlideView.imageView.image = self.myImage5;
}
And the above code works, if for, example, I click on button 5, as it sets image5 to the view in the “SelectSlideViewController”.
However, I would like to have multiple buttons using the same “selectSlide” action – and to do that, I need to figure out which button was pressed, and then assign the correct image to the “SelectSlideViewController” from an array of images (or a series of if-else statements which is clunky).
• So my revised code is as follows, but it doesn’t work with the array – any thoughts?:
- (IBAction) selectSlide:(id) sender
{
if(self.selectSlideView == nil)
{
SelectSlideViewController *viewController = [[SelectSlideViewController alloc]
initWithNibName:#"SelectSlideViewController" bundle:[NSBundle mainBundle]];
self.selectSlideView = viewController;
[viewController release];
}
NSUInteger tmpInt = -1;
tmpInt = [buttonArray indexOfObject:sender];
[self.navigationController pushViewController:self.selectSlideView animated:YES];
self.selectSlideView.cmn = cmn;
self.selectSlideView.title = cmn.name;
NSLog(#"The int was %d",tmpInt);
NSLog(#"This is the image array size %d ",[imageArray count]);
If(tmpInt >-1 && tmpInt <9)
{
self.selectSlideView.imageView.image = [imageArray objectAtIndex:tmpInt];
}
/** this code works, but is a bit clunky:
if(tmpInt == 0)
self.selectSlideView.imageView.image = self.myImage1;
else if (tmpInt == 1)
self.selectSlideView.imageView.image = self.myImage2;
else if (tmpInt == 2)
self.selectSlideView.imageView.image = self.myImage3;
else if (tmpInt == 3)
self.selectSlideView.imageView.image = self.myImage4;
else if (tmpInt == 4)
self.selectSlideView.imageView.image = self.myImage5;
else if (tmpInt == 5)
self.selectSlideView.imageView.image = self.myImage6;
else if (tmpInt == 6)
self.selectSlideView.imageView.image = self.myImage7;
else if (tmpInt == 7)
self.selectSlideView.imageView.image = self.myImage8;
else if (tmpInt == 8)
self.selectSlideView.imageView.image = self.myImage9;
**/
}
I have definitely confirmed that the imageArray is of size 9, and that it is picking the correct index from the array, however the SelectSlideViewController doesn't display the image, if accessed from the array. It displays it if accessed using the clunky if-else statements.
You could try to load the images directly the first time, then cache afterwards. (I've excluded the caching code, and the scaling code, but you can add them after you get the image).
If(tmpInt >-1 && tmpInt <9)
{
// Check if already cached
self.selectSlideView.imageView.image = [self getButtonImages:tmpInt];
// add scaling code here for smaller image
}
In #implementation you can add:
- (UIImage) getButtonImages:(NSInteger)index
{
UIImage* myImage = [UIImage imageNamed:#"image%d.jpg", index];
return myImage;
}
Here is the solution to the above problem (credited to "JSD" from www.iphonedevsdk.com):
Since selectSlideView.imageView was loaded from a nib the view wasn't loaded the first time through.
I had to include the following line of code before I assigned images from my Array to the view:
[selectSlideView view];