UIPageViewController Page Number on Toolbar - objective-c

I have a PageViewApplication that I am writing and I am oh so nearly there! but I have a problem getting the page number to show as the title of a button I have in a toolbar.
The toolbar is activated when a user taps once on the image in the pageviewcontroller and on this toolbar is a button, which I am told, is the best way to display the page number.
I have written the following where _currentPageNumber is an Integer of the current Index
NSString *strTotalPages = [NSString stringWithFormat:#"%d", NrOfImages];
_pageNumbering.title = [NSString stringWithFormat:#"%d / %#", _currentPageNumber, strTotalPages];
My issue is where to place this as at the moment it is just showing 0
Any help would be great
Thanks

I use this function and is working fine
- (NSUInteger)indexOfViewController:(LeafletPageContentViewController *)viewController {
return [self.modelArray indexOfObject:viewController.dataObject]; }
modelArray is the array with the data of each view
Then, when I want to know the current index use this
ClassOfMyViewController *currentViewController = [self.pageViewController.viewControllers objectAtIndex:0];
NSUInteger retreivedIndex = [self indexOfViewController:currentViewController];

If you're changing the title of a button on a toolbar then you will need to remove/re-create and add the button to the toolbar as it isn't quite as simple as just changing the title of the button with a string value.
Essentially redrawing it should solve the issue.

I struggled with this problem, but the pageViewController doesn't provide a method to retrieve the current page.
So, if you use the method pageControllerAfterPageController or pageControllerBeforePageController you should get a wrong page number: in fact, if you swipe your finger to change page, but you don't complete the swipe, the page showed remains the same, but your counter show the previous or next page number.
So, you can try to use viewDidLoad method of your contentViewController for update the counter and the button !

Related

Click on UILabel and perform action

I have a simple problem, I have a string like "#my#name#is#umesh#verma" and assign to a UITableview cell label,
cell.detaillabel.text = #"#my#name#is#umesh#verma";
My Problem is how to get each word name when I click on single item.
If I click on #umesh then I get "umesh" word..
More better solution is add custom label which supports touches. For example TTTAttributedLabel supports touches on links.
Main task is get notification when user touch a word and to identify the word.
You can add URLs (with special format) to any word and subscribe to a notification when user click it (as delegate to the label). For example you can create this URL for "word":
touchscheme://word
I haven't checked about how to perform an action when clicking on a UILabel. However, I experienced that with UITextView. You can use "NSLinkAttributeName" to do that.
Basically, from your original string, try to find the range of string that you need to trigger actions. Then add a link value.
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:yourString];
[attributedString addAttribute:NSLinkAttributeName value:url range:range];
[textView setAttributedText:attributedString];
Set delegate to your textView and handle the following method
-(BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange{
// You can retrive your string here or perform an action
return YES;
}
Hope this would be helpful for you.

backBarButtonItem with popViewController and swipe

My App logic is like that: VCA => VCB, and there is a scroll view in VCB with swipe left and right function. Some code help to understand structure, in VCB:
self.scrollView.pagingEnabled = YES;
self.scrollView.directionalLockEnabled = YES;
self.scrollView.contentSize =CGSizeMake(CGRectGetWidth(self.scrollView.frame) * numberPages, CGRectGetHeight(self.scrollView.frame));
so what I want is list some pages horizontally and swipe to left and right to navigate. Each page has it own view controller(child view controller of VCB) and I add them like that:
if (controller.view.superview == nil)
{
[self addChildViewController:controller];
[self.scrollView addSubview:controller.view];
[controller didMoveToParentViewController:self];
}
So far it works fine for iOS 6. I can swipe to change page. All function inside each page also works fine.
Then the problem comes with iOS 7's new feature, swipe to right to automatically call popViewControllerAnimated:, same effect like click go back button. To solve the conflict, I disable the interactivePopGestureRecognizer: self.navigationController.interactivePopGestureRecognizer.enabled = NO;
and it works ok, no force to pop back when I just want to swipe change the page.
Now the real problem. I set a back button(backBarButtonItem) on navigation bar. Every time I use that button pop from VCB back to VCA and current page is not the first page (that means there is at least one page on the left side), the pop animation is like first change page to the left side one, then immediately show VCA without any animation.
So any solution? Please help me.
First of all, it is hard to determine the problem without any piece of your code.
And secondly, why won't you create the button yourself, and add a target to it, a function that'll dismiss / pop the view controller?

iOS - Only first line of text is viewable

In two places in our app the text that the user types in only shows first line of text. Both occurances are in external frameworks, first in UIActivityView, the other in Freshdesk MobiHelp.
First, with UIActivityView, when using Twitter:
The problem is that if the text goes beyond one row in the modal, the text goes transparent:
NSString *textToShare = [NSString stringWithFormat:NSLocalizedString(#"CHALLENGE-TWITTER- DEFAULT-TEXT", nil), [UserManager currentUser].displayName];
NSString *urlToShare = [NSURL URLWithString:#"http://example.com"];
NSArray *activityItems = #[textToShare, urlToShare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];
Second, in Freshdesk submit a ticket:
I should also add that the Facebook modal from UIActivityView works just fine:
Would really appreciate any tips here, as I'm lost.
I think in the second sreenshot that you have attached here, there is a white screen over a red area which probably might be your label or the text area and I guess its blocking your text area. If the view was added by you, you can get the particular text area to front so that its not blocked and you can see your text. Hope this helps
Can you see a white box inside the one I highlighted? There is some view over your textarea. How are you adding your textarea? As a subview?? Can you just get log the main views subviews?? Like
NSLog (#"%#",[self.view subviews]);
And now check the view hierarchy.

UITableView setContentOffset but don't scroll tableView?

I am using setContentOffset on a UITableView because I want to initially hide a search field that is my tableHeaderView.
[self.tableView setContentOffset:CGPointMake(0, 56)]; // No scroll please!
Each time I push a new viewController I want to hide the search bar with contentOffset. But when I pop a viewController that offset is no longer in effect for some reason and shows the search bar. Why is this?
you can try and implement it on the following
- (void)viewWillAppear:(BOOL)animated {
[self.tableView setContentOffset:CGPointMake(0, 56)];
}
that will put the table in the correct position before it is displayed on the screen, I am assuming you mean no animation while setting the position.
I am guessing that you want to stop the user being able to scroll to the very top of the screen. If so you can implement the following UITableView delegate (on iOS5 and above):
scrollViewWillEndDragging:withVelocity:targetContentOffset:
which allows you to modify the final target for a change in the contentOffset. In the implementation you do:
- (void)scrollViewWillEndDragging:(UIScrollView *)theScrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
if(targetContentOffset->y < 56) {
targetContentOffset->y=56;
}
}
If you are trying to preserve the value of something during an action that loses it, the natural solution is to hold onto it yourself ("Hold/Restore"):
"Hold": get content offset to a field or local variable. Apple doc
.. do whatever you want.
"Restore": set content offset to the value you got above.
(Sorry, I don't write Objective C code, so can't provide the exact code. An edit to add the code, would be welcome.)
In a different situation, it might be necessary to hold the row you were at, and then scroll back to that row:
(Adapted from: https://stackoverflow.com/a/34270078/199364)
(Swift)
1. Hold current row.
let holdIndexPath = tableView.indexPathForSelectedRow()
.. do whatever (perhaps ending with "reloadData").
Restore held row:
// The next line is to make sure the row object exists.
tableView.reloadRowsAtIndexPaths([holdIndexPath], withRowAnimation: .None)
tableView.scrollToRowAtIndexPath(holdIndexPath, atScrollPosition: atScrollPosition, animated: true)

How to select only center image of iCarousel?

I have a iCarousel gallery in which I am getting images from web service. The gallery showing perfectly. I used iCarasouel delegate method "didSelectItemAtIndex" for selecting the First to last image. My icarousel type is "carousel.type = iCarouselTypeCoverFlow;".
I selected the image and i got proper index of image, didSelectItemAtIndex works properly only when I scroll gallery and image is moved from center, but when the view is load "Frist or any images" are showing in center are not selected by didSelectItemAtIndex. when I scroll the gallery again and center image is moved from the center then its works fine, then I am able to select the image and go to the next Class or view.
I want to select image which are showing in the center of Icaraosel. Don't know how to do it?
Any hints from experts would be very welcome.
You can get the current index of the image in the given below delegate method
- (void)carouselCurrentItemIndexUpdated:(iCarousel *)carousel1
Once your images load s completely then call
[self carouselCurrentItemIndexUpdated:carousel];
Here is the code :
In your viewDidLoad call the method as shown below,here carsousel is in an instance of iCarsouel.
- (void)viewDidLoad
{
[super viewDidLoad];
[self carouselCurrentItemIndexUpdated:carousel];
}
- (void)carouselCurrentItemIndexUpdated:(iCarousel *)carousel1
{
self.currentItem=carousel1.currentItemIndex;
NSLog(#"currentItem update== %i",self.currentItem);
}
Hope this helps....
I dont know if I understood you right: you want to get a didSelectItemAtIndex: message right after the initial reload of the view and without scrolling?
just ask for currentItemIndex and if you want the selected to be center always call centerItemWhenSelected
so just call [self didSelectItemAtIndex:carousel.currentItemIndex];` manually
-(void)carousel:(iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index
{
if (index == carousel.currentItemIndex)
{
///Selected centered item only
}
}