How to hide/Remove the search bar on Contact Picker - iphone

I am adding a contact picker in my app, however, I do not want the search functionality.
How to hide/Remove the search bar on Contact Picker (ABPeoplePickerNavigationController)?

static BOOL foundSearchBar = NO;
- (void)findSearchBar:(UIView*)parent mark:(NSString*)mark {
for( UIView* v in [parent subviews] ) {
//if( foundSearchBar ) return;
NSLog(#"%#%#",mark,NSStringFromClass([v class]));
if( [v isKindOfClass:[UISearchBar class]] ) {
[(UISearchBar*)v setTintColor:[UIColor blackColor]];
v.hidden=YES;
// foundSearchBar = YES;
break;
}
if( [v isKindOfClass:[UITableView class]] ) {
CGRect temp =v.frame;
temp.origin.y=temp.origin.y-44;
temp.size.height=temp.size.height+44;
v.frame=temp;
//foundSearchBar = YES;
break;
}
[self findSearchBar:v mark:[mark stringByAppendingString:#"> "]];
}
}
call above method after picker is presented as below:
-(void)showPeoplePickerController
{
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
picker.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;
// Display only a person's phone, email, and birthdate
NSArray *displayedItems = [NSArray arrayWithObjects:[NSNumber numberWithInt:kABPersonPhoneProperty],
[NSNumber numberWithInt:kABPersonEmailProperty],
[NSNumber numberWithInt:kABPersonBirthdayProperty],[NSNumber numberWithInt:kABPersonAddressProperty],nil];
picker.displayedProperties = displayedItems;
// Show the picker
[self presentViewController:picker animated:YES completion:nil];
[self findSearchBar:[picker view] mark:#"> "];
[picker release];
}

-(void)showAddressBook {
ABPeoplePickerNavigationController *addressBook = [[ABPeoplePickerNavigationController alloc] init];
[addressBook setPeoplePickerDelegate:self];
addressBook.delegate = self;
addressBook.navigationBar.topItem.title = #"iPhone Contacts";
UIView *view = addressBook.topViewController.view;
for (UIView *v in view.subviews) {
if ( [v isKindOfClass:[UITableView class]] ) {
CGRect temp = v.frame;
temp.origin.y = temp.origin.y - 44;
temp.size.height = temp.size.height + 44;
v.frame = temp;
}
}
[addressBook release];
}
- (void)navigationController:(UINavigationController*)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
if ([navigationController isKindOfClass:[ABPeoplePickerNavigationController class]]) {
UISearchDisplayController *searchDisplayController = navigationController.topViewController.searchDisplayController;
[searchDisplayController.searchBar setHidden:YES];
}
}

Related

Keyboard is not resigning when tapping uipickerview

I have two UIPickerView and one UITextField in my search view. Everything was working fine when I Input/Select the two UIPickerView first and then I input UITextField.
But when I change the order like Inputting UITextField then selecting UIPickerView, the problem happening is keyboard is not resigned when I tap on the UIPickerViews.
Below is my code
- (void) textFieldDidBeginEditing: (UITextField *) textField
//---------------------------------------------------------------
{
if (textField == self.txtFieldPoetName) {
NSLog(#"sdsdfsd");
[textField resignFirstResponder];
if ( [self.poetNameArray count] > 0 ){
[self showPoetNamePicker];
}
}
else if (textField == self.txtFieldPoemType) {
NSLog(#"jdjdjdjd");
[textField resignFirstResponder];
if( [self.poemTypeArray count] > 0 ){
[self showPoemTypePicker];
}
}
}
- (void) textFieldDidEndEditing:(UITextField *)textField{
[textField resignFirstResponder];
}
- (void)showPoetNamePicker {
[self resignKeyboard];
startXMLParser_ = NO;
self.actionSheet = [[[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]autorelease];
self.actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
self.actionSheet.title = #"Poet Name";
self.poetNamePicker = [[[UIPickerView alloc] init]autorelease];
self.poetNamePicker.showsSelectionIndicator = YES;
self.poetNamePicker.dataSource = self;
self.poetNamePicker.delegate = self;
PickerType = 1;
//Set up the display frame
self.poetNamePicker.frame = CGRectMake(0, 35, 320, 120);
//Add the picker to the view
[self.actionSheet addSubview:self.poetNamePicker];
UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:#"Done"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(260, 6.0f, 50.0f, 27.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blackColor];
[closeButton addTarget:self action:#selector(hidePicker:) forControlEvents:UIControlEventValueChanged];
[self.actionSheet addSubview:closeButton];
[closeButton release];
[self.actionSheet showInView:self.appDelegate.tabBarController.view];
[self.actionSheet setBounds:CGRectMake(0, 0, 320, 385)];
}
- (void)showPoemTypePicker {
[self resignKeyboard];
startXMLParser_ = YES;
self.actionSheet = [[[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]autorelease];
self.actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
self.actionSheet.title = #"Poem Type";
self.poemTypePicker = [[[UIPickerView alloc] init]autorelease];
self.poemTypePicker.showsSelectionIndicator = YES;
self.poemTypePicker.dataSource = self;
self.poemTypePicker.delegate = self;
PickerType = 2;
//Set up the display frame
self.poemTypePicker.frame = CGRectMake(0, 35, 320, 120);
//Add the picker to the view
[self.actionSheet addSubview:self.poemTypePicker];
UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:#"Done"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(260, 6.0f, 50.0f, 27.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blackColor];
[closeButton addTarget:self action:#selector(hidePicker:) forControlEvents:UIControlEventValueChanged];
[self.actionSheet addSubview:closeButton];
[closeButton release];
[self.actionSheet showInView:self.appDelegate.tabBarController.view];
[self.actionSheet setBounds:CGRectMake(0, 0, 320, 385)];
}
- (void)hidePicker:(id)sender
{
if( PickerType == 1 )
{
if ( [self.poetNameArray count] > 0 &&
[self.txtFieldPoetName.text length] == 0 )
{
//self.poemTypeId = #"";
self.txtFieldPoetName.text = [self.poetNameArray objectAtIndex:0];
self.poetTypeId = [self.poetTypeIdArray objectAtIndex:0];
}
}
else if( PickerType == 2 )
{
if ( [self.poemTypeArray count] > 0 &&
[self.txtFieldPoemType.text length] == 0)
{
//self.poetTypeId = #"";
self.txtFieldPoemType.text = [self.poemTypeArray objectAtIndex:0];
self.poemTypeId = [self.poemTypeIdArray objectAtIndex:0];
}
}
[self resignFirstResponder];
self.actionSheet.hidden = YES;
[self.actionSheet dismissWithClickedButtonIndex:1 animated:YES];
if (startXMLParser_)
{
[self performSelector:#selector(startXMLParsing) withObject:nil afterDelay:0.5];
}
}
-(void)resignKeyboard{
[self.txtFieldPoetName resignFirstResponder];
[self.txtFieldPoemName resignFirstResponder];
[self.txtFieldPoemType resignFirstResponder];
}
EDIT :
- (void) textFieldShouldBeginEditing: (UITextField *) textField
{
if (textField == self.txtFieldPoetName)
{
if( [self.poemNameArray count] > 0 ){
[self showPoetNamePicker];
}
return NO;
}
else if (textField == self.txtFieldPoemType)
{
if( [self.poemTypeArray count] > 0 ){
[self showPoemTypePicker];
}
return NO;
}
else
{
return YES;
}
}
In showPoetNamePicker add this:
- (void)showPoetNamePicker
{
[self.view endEditing:YES];
........
........
}
Have you linked to delegate properly?
Try changing this method,
-(void)resignKeyboard{
[self.view endEditing:YES];
}
I know this is an old question, but I think it should be mentioned ... I think the better solution is to use inputView (and optionally inputAccessoryView) of each textField. Something like that:
-(void)setupTextFields{
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
toolbar.items = [NSArray arrayWithObjects:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(endEditing)], nil];
self.txtFieldPoetName.inputView = self.poetNamePicker;
self.txtFieldPoetName.inputAccessoryView = toolbar;
self.txtFieldPoemType.inputView = self.poetTypePicker;
self.txtFieldPoemType.inputAccessoryView = toolbar;
}
-(void)endEditing{
[self.txtFieldPoetName resignFirstResponder];
[self.txtFieldPoemType resignFirstResponder];
}
OS ensures switching picker for keyboard and vice versa (it's displayed in same view as keyboard I guess).

How to load a tabbar controller xib using navigation controller

I am new to ios, I had a problem with tabbar controller. I am using two tab bar controller in my project.One is loaded at app lunch and it is working good.I want to load another at didselect row.How to do this. I have done many experiments but nothing works.
-(void) hidetabbar {
[UIView animateWithDuration:0.5
animations:^{
for(UIView *view in tabBarController.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
if (hiddenTabBar) {
[view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
}
} else {
if (hiddenTabBar) {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
}
}];
hiddenTabBar = !hiddenTabBar;
}
when u r clicking on the table view did select row hide the tabbar in the viewcontroller that u r sending
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:YES];
[((AppDelegate*)[[UIApplication sharedApplication]delegate]) hidetabbar];
}
-(void)tabBarControllerView
{
tabBarController = [[UITabBarController alloc] init];
tabBarController.view.backgroundColor = [UIColor blackColor];
tabBarController.delegate = self;
//Add some tabs to the controller...
//----First tab----//
//-----second Tab -----//
//------3rd tab--//
//-----4th tab bar--------//
//-----5th tab bar--------//
[self.view addSubview:tabBarController.view];
[navigationController pushViewController:tabBarController animated:YES];
tabBarController.tabBar.tag=100;
tabBarController.view.hidden = NO;
}
- (void)tabBarController:(UITabBarController *)tabBarControllers didSelectViewController:(UIViewController *)viewController
{
if (tabBarControllers.selectedIndex == 0)
{
}
else if (tabBarControllers.selectedIndex == 1)
{
}
else if (tabBarControllers.selectedIndex == 2)
{
}
else if (tabBarControllers.selectedIndex == 3)
{
}
else if (tabBarControllers.selectedIndex == 4)
{
}
}
hide main tab bar in that view controller where u r doing the did select table and add another tab bar..
try some thing like this it may help u
Add the following Code in didSelect event
UITabBarController *tabBarController = [[UITabBarController alloc]init];
NSArray*tabBarimageArray=[NSArray arrayWithObjects:#"firstTabImage.png",#"secondTabImage.png", nil];
YourFirstTabRootViewController *firstVc = [[YourFirstTabRootViewController alloc]initWithNibName:#"YourFirstTabRootViewController" bundle:nil];
UINavigationController *firstNavigationController=[[UINavigationController alloc]initWithRootViewController:firstVc];
YourSecondTabRootViewController *secondVc = [[YourSecondTabRootViewController alloc]initWithNibName:#"YourFirstTabRootViewController" bundle:nil];
UINavigationController *secondNavigationController=[[UINavigationController alloc]initWithRootViewController:secondVc];
NSArray *VCs = [[NSArray alloc] initWithObjects:firstNavigationController,secondNavigationController nil];
NSArray *names = [NSArray arrayWithObjects:
NSLocalizedString(#"Tab1", #""),
NSLocalizedString(#"Tab2", #""),
nil];
NSMutableArray *tabBarViewControllers = [[NSMutableArray alloc] initWithCapacity:[VCs count]];
NSInteger index = 0;
for (id controller in VCs) {
UINavigationController * navController = controller ;
// THIS SETS UP THE TAB BAR ITEMS/IMAGES AND SET THE TAG FOR TABBAR_ITEM_TAGS
NSString *tabName = [names objectAtIndex:index];
UIImage *tabImage = [UIImage imageNamed:[NSString stringWithFormat:[tabBarimageArray objectAtIndex:index]]];
navController.title = tabName;
UITabBarItem *tempTab = [[UITabBarItem alloc] initWithTitle:tabName
image:tabImage
tag:index];
navController.tabBarItem = tempTab;
[tabBarViewControllers addObject:navController];
index ++;
}
[ tabBarController setViewControllers:tabBarViewControllers];
[self presentModalViewController:tabBarController animated:YES];

iphone FullScreen navigation bar displacement

I implemented an app Images in full screen are displayed fine.
After few seconds the navigation bar and status bar are hidden, now if i close the app and again open it, the navigation bar is displaced at the top of the screen where status bar overlaps on navigation bar
I guess i have to change something about the CGRect frame
Please help me
#import "KTPhotoScrollViewController.h"
#import "KTPhotoBrowserDataSource.h"
#import "KTPhotoBrowserGlobal.h"
#import "KTPhotoView.h"
const CGFloat ktkDefaultPortraitToolbarHeight = 44;
const CGFloat ktkDefaultLandscapeToolbarHeight = 33;
const CGFloat ktkDefaultToolbarHeight = 44;
#define BUTTON_DELETEPHOTO 0
#define BUTTON_CANCEL 1
#interface KTPhotoScrollViewController (KTPrivate)
- (void)setCurrentIndex:(NSInteger)newIndex;
- (void)toggleChrome:(BOOL)hide;
- (void)startChromeDisplayTimer;
- (void)cancelChromeDisplayTimer;
- (void)hideChrome;
- (void)showChrome;
- (void)swapCurrentAndNextPhotos;
- (void)nextPhoto;
- (void)previousPhoto;
- (void)toggleNavButtons;
- (CGRect)frameForPagingScrollView;
- (CGRect)frameForPageAtIndex:(NSUInteger)index;
- (void)loadPhoto:(NSInteger)index;
- (void)unloadPhoto:(NSInteger)index;
- (void)trashPhoto;
- (void)exportPhoto;
#end
#implementation KTPhotoScrollViewController
#synthesize statusBarStyle = statusBarStyle_;
#synthesize statusbarHidden = statusbarHidden_;
#synthesize my_img, imgURL;
- (void)dealloc
{
[nextButton_ release], nextButton_ = nil;
[previousButton_ release], previousButton_ = nil;
[scrollView_ release], scrollView_ = nil;
[toolbar_ release], toolbar_ = nil;
[photoViews_ release], photoViews_ = nil;
[dataSource_ release], dataSource_ = nil;
[super dealloc];
}
- (id)initWithDataSource:(id <KTPhotoBrowserDataSource>)dataSource andStartWithPhotoAtIndex:(NSUInteger)index
{
if (self = [super init]) {
startWithIndex_ = index;
dataSource_ = [dataSource retain];
// Make sure to set wantsFullScreenLayout or the photo
// will not display behind the status bar.
[self setWantsFullScreenLayout:YES];
BOOL isStatusbarHidden = [[UIApplication sharedApplication] isStatusBarHidden];
[self setStatusbarHidden:isStatusbarHidden];
self.hidesBottomBarWhenPushed = YES;
}
return self;
}
- (void)loadView
{
[super loadView];
CGRect scrollFrame = [self frameForPagingScrollView];
UIScrollView *newView = [[UIScrollView alloc] initWithFrame:scrollFrame];
[newView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
[newView setDelegate:self];
UIColor *backgroundColor = [dataSource_ respondsToSelector:#selector(imageBackgroundColor)] ?
[dataSource_ imageBackgroundColor] : [UIColor blackColor];
[newView setBackgroundColor:backgroundColor];
[newView setAutoresizesSubviews:YES];
[newView setPagingEnabled:YES];
[newView setShowsVerticalScrollIndicator:NO];
[newView setShowsHorizontalScrollIndicator:NO];
[[self view] addSubview:newView];
scrollView_ = [newView retain];
[newView release];
nextButton_ = [[UIBarButtonItem alloc]
initWithImage:[UIImage imageNamed:#"nextIcon.png"]
style:UIBarButtonItemStylePlain
target:self
action:#selector(nextPhoto)];
previousButton_ = [[UIBarButtonItem alloc]
initWithImage:[UIImage imageNamed:#"previousIcon.png"]
style:UIBarButtonItemStylePlain
target:self
action:#selector(previousPhoto)];
UIBarButtonItem *msgButton = nil;
UIBarButtonItem *exportButton = nil;
exportButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:self
action:#selector(exportPhoto)];
msgButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks
target:self
action:#selector(msgPhoto)];
// UIImage *image = [UIImage imageNamed:#"Icon-Small"];
// UIButton *myMuteButton = [UIButton buttonWithType:UIButtonTypeCustom];
// myMuteButton.bounds = CGRectMake( 0, 0, image.size.width, image.size.height );
// [myMuteButton setImage:image forState:UIControlStateNormal];
// [myMuteButton addTarget:self action:#selector(trashPhoto) forControlEvents:UIControlEventTouchUpInside];
// UIBarButtonItem *myMuteBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:myMuteButton];
UIBarItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
NSMutableArray *toolbarItems = [[NSMutableArray alloc] initWithCapacity:7];
if (exportButton) [toolbarItems addObject:exportButton];
[toolbarItems addObject:space];
[toolbarItems addObject:previousButton_];
[toolbarItems addObject:space];
[toolbarItems addObject:nextButton_];
[toolbarItems addObject:space];
if (msgButton) [toolbarItems addObject:msgButton];
// [toolbarItems addObject:myMuteBarButtonItem];
// [myMuteBarButtonItem release];
CGRect screenFrame = [[UIScreen mainScreen] bounds];
CGRect toolbarFrame = CGRectMake(0,
screenFrame.size.height - ktkDefaultToolbarHeight,
screenFrame.size.width,
ktkDefaultToolbarHeight);
toolbar_ = [[UIToolbar alloc] initWithFrame:toolbarFrame];
[toolbar_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin];
[toolbar_ setBarStyle:UIBarStyleBlackTranslucent];
[toolbar_ setItems:toolbarItems];
[[self view] addSubview:toolbar_];
if (msgButton) [msgButton release];
if (exportButton) [exportButton release];
[toolbarItems release];
[space release];
}
- (void) ShowAlert:(NSString*)title MyMsg:(NSString*)msg{
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
[alert autorelease];
}
- (void)setTitleWithCurrentPhotoIndex
{
NSString *formatString = NSLocalizedString(#"%1$i of %2$i", #"Picture X out of Y total.");
NSString *title = [NSString stringWithFormat:formatString, currentIndex_ + 1, photoCount_, nil];
[self setTitle:title];
}
- (void)scrollToIndex:(NSInteger)index
{
CGRect frame = scrollView_.frame;
frame.origin.x = frame.size.width * index;
frame.origin.y = 0;
[scrollView_ scrollRectToVisible:frame animated:NO];
}
- (void)setScrollViewContentSize
{
NSInteger pageCount = photoCount_;
if (pageCount == 0) {
pageCount = 1;
}
CGSize size = CGSizeMake(scrollView_.frame.size.width * pageCount,
scrollView_.frame.size.height / 2); // Cut in half to prevent horizontal scrolling.
[scrollView_ setContentSize:size];
}
- (void)viewDidLoad
{
[super viewDidLoad];
photoCount_ = [dataSource_ numberOfPhotos];
[self setScrollViewContentSize];
// Setup our photo view cache. We only keep 3 views in
// memory. NSNull is used as a placeholder for the other
// elements in the view cache array.
photoViews_ = [[NSMutableArray alloc] initWithCapacity:photoCount_];
for (int i=0; i < photoCount_; i++) {
[photoViews_ addObject:[NSNull null]];
}
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// The first time the view appears, store away the previous controller's values so we can reset on pop.
UINavigationBar *navbar = [[self navigationController] navigationBar];
if (!viewDidAppearOnce_) {
viewDidAppearOnce_ = YES;
navbarWasTranslucent_ = [navbar isTranslucent];
statusBarStyle_ = [[UIApplication sharedApplication] statusBarStyle];
}
// Then ensure translucency. Without it, the view will appear below rather than under it.
[navbar setTranslucent:YES];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];
// Set the scroll view's content size, auto-scroll to the stating photo,
// and setup the other display elements.
[self setScrollViewContentSize];
[self setCurrentIndex:startWithIndex_];
[self scrollToIndex:startWithIndex_];
[self setTitleWithCurrentPhotoIndex];
[self toggleNavButtons];
[self startChromeDisplayTimer];
}
- (void)viewWillDisappear:(BOOL)animated
{
// Reset nav bar translucency and status bar style to whatever it was before.
UINavigationBar *navbar = [[self navigationController] navigationBar];
[navbar setTranslucent:navbarWasTranslucent_];
[[UIApplication sharedApplication] setStatusBarStyle:statusBarStyle_ animated:YES];
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[self cancelChromeDisplayTimer];
[super viewDidDisappear:animated];
}
- (void)deleteCurrentPhoto
{
if (dataSource_) {
// TODO: Animate the deletion of the current photo.
NSInteger photoIndexToDelete = currentIndex_;
[self unloadPhoto:photoIndexToDelete];
[dataSource_ deleteImageAtIndex:photoIndexToDelete];
photoCount_ -= 1;
if (photoCount_ == 0) {
[self showChrome];
[[self navigationController] popViewControllerAnimated:YES];
} else {
NSInteger nextIndex = photoIndexToDelete;
if (nextIndex == photoCount_) {
nextIndex -= 1;
}
[self setCurrentIndex:nextIndex];
[self setScrollViewContentSize];
}
}
}
- (void)toggleNavButtons
{
[previousButton_ setEnabled:(currentIndex_ > 0)];
[nextButton_ setEnabled:(currentIndex_ < photoCount_ - 1)];
}
#pragma mark -
#pragma mark Frame calculations
#define PADDING 20
- (CGRect)frameForPagingScrollView
{
CGRect frame = [[UIScreen mainScreen] bounds];
frame.origin.x -= PADDING;
frame.size.width += (2 * PADDING);
return frame;
}
- (CGRect)frameForPageAtIndex:(NSUInteger)index
{
CGRect bounds = [scrollView_ bounds];
CGRect pageFrame = bounds;
pageFrame.size.width -= (2 * PADDING);
pageFrame.origin.x = (bounds.size.width * index) + PADDING;
return pageFrame;
}
#pragma mark -
#pragma mark Photo (Page) Management
- (void)loadPhoto:(NSInteger)index
{
if (index < 0 || index >= photoCount_) {
return;
}
id currentPhotoView = [photoViews_ objectAtIndex:index];
if (NO == [currentPhotoView isKindOfClass:[KTPhotoView class]]) {
// Load the photo view.
CGRect frame = [self frameForPageAtIndex:index];
KTPhotoView *photoView = [[KTPhotoView alloc] initWithFrame:frame];
[photoView setScroller:self];
[photoView setIndex:index];
[photoView setBackgroundColor:[UIColor clearColor]];
// Set the photo image.
if (dataSource_) {
if ([dataSource_ respondsToSelector:#selector(imageAtIndex:photoView:)] == NO) {
UIImage *image = [dataSource_ imageAtIndex:index];
[photoView setImage:image];
} else {
[dataSource_ imageAtIndex:index photoView:photoView];
}
}
[scrollView_ addSubview:photoView];
[photoViews_ replaceObjectAtIndex:index withObject:photoView];
[photoView release];
} else {
// Turn off zooming.
[currentPhotoView turnOffZoom];
}
}
- (void)unloadPhoto:(NSInteger)index
{
if (index < 0 || index >= photoCount_) {
return;
}
id currentPhotoView = [photoViews_ objectAtIndex:index];
if ([currentPhotoView isKindOfClass:[KTPhotoView class]]) {
[currentPhotoView removeFromSuperview];
[photoViews_ replaceObjectAtIndex:index withObject:[NSNull null]];
}
}
- (void)setCurrentIndex:(NSInteger)newIndex
{
currentIndex_ = newIndex;
if(newIndex>=0){
myUrl = [dataSource_ imageURLAtIndex:currentIndex_ photoView:[photoViews_ objectAtIndex:currentIndex_]];
myDescr = [dataSource_ imageDESCRAtIndex:currentIndex_ photoView:[photoViews_ objectAtIndex:currentIndex_]];
img_Title =[dataSource_ imageimg_TitleAtIndex:currentIndex_ photoView:[photoViews_ objectAtIndex:currentIndex_]];
}
[self loadPhoto:currentIndex_];
[self loadPhoto:currentIndex_ + 1];
[self loadPhoto:currentIndex_ - 1];
[self unloadPhoto:currentIndex_ + 2];
[self unloadPhoto:currentIndex_ - 2];
[self setTitleWithCurrentPhotoIndex];
[self toggleNavButtons];
}
#pragma mark -
#pragma mark Rotation Magic
- (void)updateToolbarWithOrientation:(UIInterfaceOrientation)interfaceOrientation
{
CGRect toolbarFrame = toolbar_.frame;
if ((interfaceOrientation) == UIInterfaceOrientationPortrait || (interfaceOrientation) == UIInterfaceOrientationPortraitUpsideDown) {
toolbarFrame.size.height = ktkDefaultPortraitToolbarHeight;
} else {
toolbarFrame.size.height = ktkDefaultLandscapeToolbarHeight+1;
}
toolbarFrame.size.width = self.view.frame.size.width;
toolbarFrame.origin.y = self.view.frame.size.height - toolbarFrame.size.height;
toolbar_.frame = toolbarFrame;
}
- (void)layoutScrollViewSubviews
{
[self setScrollViewContentSize];
NSArray *subviews = [scrollView_ subviews];
for (KTPhotoView *photoView in subviews) {
CGPoint restorePoint = [photoView pointToCenterAfterRotation];
CGFloat restoreScale = [photoView scaleToRestoreAfterRotation];
[photoView setFrame:[self frameForPageAtIndex:[photoView index]]];
[photoView setMaxMinZoomScalesForCurrentBounds];
[photoView restoreCenterPoint:restorePoint scale:restoreScale];
}
// adjust contentOffset to preserve page location based on values collected prior to location
CGFloat pageWidth = scrollView_.bounds.size.width;
CGFloat newOffset = (firstVisiblePageIndexBeforeRotation_ * pageWidth) + (percentScrolledIntoFirstVisiblePage_ * pageWidth);
scrollView_.contentOffset = CGPointMake(newOffset, 0);
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
{
// here, our pagingScrollView bounds have not yet been updated for the new interface orientation. So this is a good
// place to calculate the content offset that we will need in the new orientation
CGFloat offset = scrollView_.contentOffset.x;
CGFloat pageWidth = scrollView_.bounds.size.width;
if (offset >= 0) {
firstVisiblePageIndexBeforeRotation_ = floorf(offset / pageWidth);
percentScrolledIntoFirstVisiblePage_ = (offset - (firstVisiblePageIndexBeforeRotation_ * pageWidth)) / pageWidth;
} else {
firstVisiblePageIndexBeforeRotation_ = 0;
percentScrolledIntoFirstVisiblePage_ = offset / pageWidth;
}
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
{
[self layoutScrollViewSubviews];
// Rotate the toolbar.
[self updateToolbarWithOrientation:toInterfaceOrientation];
// Adjust navigation bar if needed.
if (isChromeHidden_ && statusbarHidden_ == NO) {
UINavigationBar *navbar = [[self navigationController] navigationBar];
CGRect frame = [navbar frame];
frame.origin.y = 20;
[navbar setFrame:frame];
}
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[self startChromeDisplayTimer];
}
- (UIView *)rotatingFooterView
{
return toolbar_;
}
#pragma mark -
#pragma mark Chrome Helpers
- (void)toggleChromeDisplay
{
[self toggleChrome:!isChromeHidden_];
}
- (void)toggleChrome:(BOOL)hide
{
isChromeHidden_ = hide;
if (hide) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.4];
}
if ( ! [self isStatusbarHidden] ) {
if ([[UIApplication sharedApplication] respondsToSelector:#selector(setStatusBarHidden:withAnimation:)]) {
[[UIApplication sharedApplication] setStatusBarHidden:hide withAnimation:NO];
} else { // Deprecated in iOS 3.2+.
id sharedApp = [UIApplication sharedApplication]; // Get around deprecation warnings.
[sharedApp setStatusBarHidden:hide animated:NO];
}
}
CGFloat alpha = hide ? 0.0 : 1.0;
// Must set the navigation bar's alpha, otherwise the photo
// view will be pushed until the navigation bar.
UINavigationBar *navbar = [[self navigationController] navigationBar];
[navbar setAlpha:alpha];
[toolbar_ setAlpha:alpha];
if (hide) {
[UIView commitAnimations];
}
if ( ! isChromeHidden_ ) {
[self startChromeDisplayTimer];
}
}
- (void)hideChrome
{
if (chromeHideTimer_ && [chromeHideTimer_ isValid]) {
[chromeHideTimer_ invalidate];
chromeHideTimer_ = nil;
}
[self toggleChrome:YES];
}
- (void)showChrome
{
[self toggleChrome:NO];
}
- (void)startChromeDisplayTimer
{
[self cancelChromeDisplayTimer];
chromeHideTimer_ = [NSTimer scheduledTimerWithTimeInterval:5.0
target:self
selector:#selector(hideChrome)
userInfo:nil
repeats:NO];
}
- (void)cancelChromeDisplayTimer
{
if (chromeHideTimer_) {
[chromeHideTimer_ invalidate];
chromeHideTimer_ = nil;
}
}
#pragma mark -
#pragma mark UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat pageWidth = scrollView.frame.size.width;
float fractionalPage = scrollView.contentOffset.x / pageWidth;
NSInteger page = floor(fractionalPage);
if (page != currentIndex_) {
[self setCurrentIndex:page];
}
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
[self hideChrome];
}
#pragma mark -
#pragma mark Toolbar Actions
- (void)nextPhoto
{
[self scrollToIndex:currentIndex_ + 1];
[self startChromeDisplayTimer];
}
- (void)previousPhoto
{
[self scrollToIndex:currentIndex_ - 1];
[self startChromeDisplayTimer];
}
- (void)msgPhoto
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:img_Title message:myDescr delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
- (void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
NSString *message;
NSString *title;
if (!error) {
title = #"Done";
message = #"image copied to your local gallery";
} else {
title = #"Error";
message = [error description];
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) {
//save to gallery
UIImage *imageB = [UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: myUrl]]];
UIImageWriteToSavedPhotosAlbum(imageB, self, #selector(imageSavedToPhotosAlbum: didFinishSavingWithError: contextInfo:), nil);
} else if (buttonIndex == 1) {
//email
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
mailComposer.toolbar.barStyle = UIBarStyleBlack;
mailComposer.title = #"Your title here";
[[mailComposer navigationBar] setTintColor:[UIColor colorWithRed:124.0/255 green:17.0/255 blue:92.0/255 alpha:1]];
if ([MFMailComposeViewController canSendMail]) {
[mailComposer setSubject:#"Look at a great image"];
[mailComposer setMessageBody:[NSString stringWithFormat:#"%#",myUrl] isHTML:NO];
UIImage *imageB = [UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: myUrl]]];
NSData *exportData = UIImageJPEGRepresentation(imageB ,1.0);
[mailComposer addAttachmentData:exportData mimeType:#"image/jpeg" fileName:img_Title];
[self presentModalViewController:mailComposer animated:YES];
}
//release the mailComposer as it is now being managed as the UIViewControllers modalViewController.
[mailComposer release];
} else if (buttonIndex == 2) {
//cancel
}
[self startChromeDisplayTimer];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
if (result == MFMailComposeResultFailed) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Failed to send message" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
- (void) exportPhoto
{
if ([dataSource_ respondsToSelector:#selector(exportImageAtIndex:)])
[dataSource_ exportImageAtIndex:currentIndex_];
[self startChromeDisplayTimer];
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Actions"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:#"Save to gallery", #"Email",nil];
[actionSheet showInView:[self view]];
[actionSheet release];
}
#end
First of all, tel me if you want to show Status Bar or not.
If you dont want to show then, in nib of controller's, you can select its view, and under its properties set StatusBar to NONE, thar time it wont show status bar... and you can set vew size to (320*480) or else with status bar it will be (320*460) and 20 pixels will be reserved for status bar.
Other ways to do (without using above method)
Can hide StatusBar from info.plist also, by setting property UIStatusBarHidden property to YES. (To hide the status bar when the app launches)
Programmatically can be done, add line to appDelegate's applicationDidFinishLaunching method,
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];

UIScrollView content not updating

I have UIScrollView in stage and paging functionality enabled to move back/next.
I have added 10 subviews in UIScrollView. When I have modify the content inside the subviews, then it is not reflected in UIScrollView.
Book.m
- (void) initializeWithXML:(NSString *)XMLURLString {
NSData *xmlData;
NSString *url;
if ( ![applicationData getMode] ) {
resourceRootURL = [[applicationData getAssetsPath] stringByAppendingPathComponent:#"phone/"];
} else {
resourceRootURL = [applicationData getAssetsPath];
}
url = [resourceRootURL stringByAppendingPathComponent:XMLURLString];
//NSLog(#"Root URL...%#", url);
if ([url rangeOfString:#"http"].location != NSNotFound) {
xmlData = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
} else {
xmlData = [NSData dataWithContentsOfFile:url];
}
bookContentArray = [self grabXML:xmlData andQuery:#"//page"];
// view controllers are created lazily
// in the meantime, load the array with placeholders which will be replaced on demand
NSMutableArray *controllers = [[NSMutableArray alloc] init];
for (unsigned i = 0; i < kNumberOfPages; i++) {
[controllers addObject:[NSNull null]];
}
self.viewControllers = controllers;
[controllers release];
for(int i = 0; i < [bookContentArray count]; i++) {
[viewControllers addObject:[NSNull null]];
}
if ( isTwoPage ) {
kNumberOfPages = [bookContentArray count];
} else {
kNumberOfPages = [bookContentArray count]/2;
}
CGRect pagingScrollViewFrame = [self frameForPagingScrollView];
scrollView = [[UIScrollView alloc] initWithFrame:pagingScrollViewFrame];
scrollView.pagingEnabled = YES;
scrollView.backgroundColor = [UIColor blackColor];
scrollView.showsVerticalScrollIndicator = NO;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.contentSize = [self contentSizeForPagingScrollView];
scrollView.contentSize = CGSizeMake(scrollView.contentSize.width,scrollView.frame.size.height);
scrollView.delegate = self;
self.view = scrollView;
kNumberOfPages = [bookContentArray count];
pageControl.numberOfPages = kNumberOfPages;
pageControl.currentPage = 0;
// pages are created on demand
// load the visible page
// load the page on either side to avoid flashes when the user starts scrolling
[self loadPage:0];
}
- (void) loadPage:(int)number {
// Calculate which pages are visible
int firstNeededPageIndex = MAX(number-1, 0);
int lastNeededPageIndex = MIN(number+1, [viewControllers count] - 1);
//NSLog(#"%d,%d",firstNeededPageIndex,lastNeededPageIndex);
// Recycle no-longer-visible pages
for(int i = 0; i < [viewControllers count]; i++) {
ImageScrollView *page = [viewControllers objectAtIndex:i];
if ((NSNull *)page != [NSNull null]) {
if (page.index < firstNeededPageIndex || page.index > lastNeededPageIndex) {
//NSLog(#"removed page %d", page.index);
[page removeImages];
[page removeFromSuperview];
page = nil;
[viewControllers replaceObjectAtIndex:i withObject:[NSNull null]];
}
}
}
// load the visible page and the page on either side of it (to avoid flashes when the user starts scrolling)
if ( number == 0 ) {
[self loadScrollViewWithPage:number];
[self loadScrollViewWithPage:number+1];
} else if ( number == [bookContentArray count]-1) {
[self loadScrollViewWithPage:number-1];
[self loadScrollViewWithPage:number];
} else {
[self loadScrollViewWithPage:number-1];
[self loadScrollViewWithPage:number];
[self loadScrollViewWithPage:number+1];
}
}
- (void)loadScrollViewWithPage:(int)page {
ImageScrollView *pageController = [[ImageScrollView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
pageController.index = page;
pageController.myDelegate = self;
pageNumber = pageControl.currentPage;
pageController.isTwoPage = isTwoPage;
if ( pageNumber == page ) {
pageController.isCurrentPage = YES;
} else {
pageController.isCurrentPage = NO;
}
[controller setImageURL:leftURL andRightURL:rightURL andPriority:0];
[scrollView addSubview:controller];
}
ImageScrollView.m
- (void) setImageURL:(NSString *)leftURL andRightURL:(NSString *)rightURL andPriority:(int)priority {
[imageView removeFromSuperview];
[imageView release];
imageView = nil;
if ( !isTwoPage ) {
imageView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
} else {
imageView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
}
if ( isTwoPage ) {
leftImage = [[FBEPage alloc] initWithNibName:#"FBEPage" bundle:nil];
leftImage.view.frame = CGRectMake(0, 43, 512, 682);
rightImage = [[FBEPage alloc] initWithNibName:#"FBEPage" bundle:nil];
rightImage.view.frame = CGRectMake(512, 43, 512, 682);
} else {
leftImage = [[FBEPage alloc] initWithNibName:#"FBEPage" bundle:nil];
leftImage.view.frame = imageView.frame;
rightImage = [[FBEPage alloc] initWithNibName:#"FBEPage" bundle:nil];
rightImage.view.frame = imageView.frame;
}
leftImage.delegate = self;
rightImage.delegate = self;
if ( isFirstPage ) {
[leftImage.view setHidden:YES];
[rightImage.view setHidden:NO];
} else if ( isLastPage ) {
[leftImage.view setHidden:NO];
[rightImage.view setHidden:YES];
} else if ( !isTwoPage ) {
[leftImage.view setHidden:NO];
[rightImage.view setHidden:YES];
} else {
[leftImage.view setHidden:NO];
[rightImage.view setHidden:NO];
}
imageView.backgroundColor = [UIColor whiteColor];
[self addSubview:imageView];
[leftImage setImageURL:leftURL];
[rightImage setImageURL:rightURL];
[imageView addSubview:leftImage.view];
[imageView addSubview:rightImage.view];
}
FBPage.m
- (void) setImageURL:(NSString *)url {
imageView = [[UIImageView alloc] init];
imageView.frame = CGRectMake(0, 0, 768, 1024);
imageView.center = self.view.center;
imageView.userInteractionEnabled = TRUE;
[container addSubview:imageView];
[activityIndicator setHidden:YES];
if ([url rangeOfString:#"http"].location != NSNotFound) {
SDWebImageManager *manager = [SDWebImageManager sharedManager];
UIImage *cachedImage = [manager imageWithURL:[NSURL URLWithString:url]];
if (cachedImage) {
[imageView setImage:cachedImage];
isImageLoaded = YES;
[self addScrollView];
} else {
[activityIndicator setHidden:NO];
[activityIndicator startAnimating];
[manager downloadWithURL:[NSURL URLWithString:url] delegate:self options:0 success:^(UIImage *image){
[activityIndicator stopAnimating];
[activityIndicator setHidden:YES];
[imageView setImage:image];
isImageLoaded = YES;
[self addScrollView];
} failure:nil];
}
imageURL = url;
} else {
imageView.image = [UIImage imageWithContentsOfFile:url];
isImageLoaded = YES;
[self addScrollView];
}
}
- (void) setHotspotURL:(NSString *)URL {
[hotspot.view removeFromSuperview];
[hotspot release];
hotspot = nil;
hotspot = [[FBHotspot alloc] initWithNibName:#"FBHotspot" bundle:nil];
hotspot.view.frame = CGRectMake(0, 0, 768, 1024);
hotspot.delegate = self;
[hotspot setURL:URL];
[container addSubview:hotspot.view];
}
**When I am calling setHotspotURL and it’s not updating to the scrollview.**
Make sure you inserted your content at the correct position within the scroll view. Set the contentSize accordingly. Try to call layoutSubviews of the UIScrollView instance

tableView:didSelectRowAtIndexPath not firing after swipe gesture is called

This is a localized issue. I'm going to post a lot of code, and provide a lot of explanation. Hopefully... someone can help me with this.
In my application I have a "Facebook-style" menu. The iOS Facebook app, to be more specific. You can access this menu in two different ways. You may either touch the menu button, or swipe to open the menu. When one opens and closes the menu using the button, the tableView:didSelectRowAtIndexPath method fires perfectly upon touching the cell. When one opens and closes the menu using the swipe method... it does not. You have to touch the table cell twice for the method to fire. The code for these methods are exactly the same in several classes, however, this is the only one I have an issue with. Take a look; see if I'm dropping the ball somewhere:
#import "BrowseViewController.h"
#implementation BrowseViewController
#synthesize browseView, table, countriesArray, btnSideHome, btnSideBrowse, btnSideFave, btnSideNew, btnSideCall, btnSideBeset, btnSideEmail, btnSideCancelled, menuOpen, navBarTitle, mainSearchBar, tap;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
label.font = [UIFont fontWithName:#"STHeitiSC-Medium" size:20.0];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:1.0];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor whiteColor];
label.text = #"Countries";
self.navBarTitle.titleView = label;
[label sizeToFit];
CheckNetworkStatus *networkCheck = [[CheckNetworkStatus alloc] init];
BOOL internetActive = [networkCheck checkNetwork];
if (internetActive) {
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(dismissKeyboard)];
[self.view addGestureRecognizer:tap];
tap.delegate = self;
tap.cancelsTouchesInView = NO;
UISwipeGestureRecognizer *oneFingerSwipeLeft =
[[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(swipeLeft:)];
[oneFingerSwipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[[self view] addGestureRecognizer:oneFingerSwipeLeft];
UISwipeGestureRecognizer *oneFingerSwipeRight =
[[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(swipeRight:)];
[oneFingerSwipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
[[self view] addGestureRecognizer:oneFingerSwipeRight];
menuOpen = NO;
table.userInteractionEnabled = YES;
NSArray *countries = [[NSArray alloc] initWithObjects:#"United States", #"Canada", #"Mexico", nil];
self.countriesArray = countries;
} else {
//No interwebz, notify user and send them to the home page
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"Connection Error" message:#"Failed to connect to the server. Please verify that you have an active internet connection and try again. If the problem persists, please call us at **********" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[message show];
PassportAmericaViewController *homeView = [[PassportAmericaViewController alloc]
initWithNibName:#"PassportAmericaViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:homeView animated:YES];
}
[super viewDidLoad];
}
-(NSInteger) tableView:(UITableView *)table numberOfRowsInSection: (NSInteger)section
{
return [countriesArray count];
NSLog(#"Number of objecits in countriesArray: %i", [countriesArray count]);
}
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.font = [UIFont fontWithName:#"STHeitiSC-Medium" size:20.0];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [countriesArray objectAtIndex:row];
return cell;
}
- (void)tableView:(UITableView *)table
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *countrySelected = [countriesArray objectAtIndex:indexPath.row];
Campground *_Campground = [[Campground alloc] init];
_Campground.country = countrySelected;
StateViewController *stateView = [[StateViewController alloc]
initWithNibName:#"StateView" bundle:[NSBundle mainBundle]];
stateView._Campground = _Campground;
[self.navigationController pushViewController:stateView animated:YES];
}
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(void) dismissKeyboard {
[mainSearchBar resignFirstResponder];
}
-(IBAction)goBack:(id)sender{
[self.navigationController popViewControllerAnimated:YES];
}
-(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
if ([animationID isEqualToString:#"slideMenu"]){
UIView *sq = (__bridge UIView *) context;
[sq removeFromSuperview];
}
}
- (IBAction)menuTapped {
NSLog(#"Menu tapped");
CGRect frame = self.browseView.frame;
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector( animationDidStop:finished:context: )];
[UIView beginAnimations:#"slideMenu" context:(__bridge void *)(self.browseView)];
if(!menuOpen) {
frame.origin.x = -212;
menuOpen = YES;
table.userInteractionEnabled = NO;
}
else
{
frame.origin.x = 0;
menuOpen = NO;
table.userInteractionEnabled = YES;
}
self.browseView.frame = frame;
[UIView commitAnimations];
}
-(IBAction) sideHome:(id)sender{
CGRect frame = self.browseView.frame;
frame.origin.x = 0;
self.browseView.frame = frame;
menuOpen = NO;
PassportAmericaViewController *homeView = [[PassportAmericaViewController alloc]
initWithNibName:#"PassportAmericaViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:homeView animated:YES];
table.userInteractionEnabled = YES;
}
-(IBAction) sideBrowse:(id)sender{
CGRect frame = self.browseView.frame;
frame.origin.x = 0;
self.browseView.frame = frame;
menuOpen = NO;
BrowseViewController *browseView2 = [[BrowseViewController alloc]
initWithNibName:#"BrowseView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:browseView2 animated:YES];
table.userInteractionEnabled = YES;
}
-(IBAction) sideBeset:(id)sender{
CGRect frame = self.browseView.frame;
frame.origin.x = 0;
self.browseView.frame = frame;
menuOpen = NO;
BesetCampgroundMapViewController *besetMapView = [[BesetCampgroundMapViewController alloc]
initWithNibName:#"BesetCampgroundMapView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:besetMapView animated:YES];
table.userInteractionEnabled = YES;
}
-(IBAction) sideFave:(id)sender{
CGRect frame = self.browseView.frame;
frame.origin.x = 0;
self.browseView.frame = frame;
menuOpen = NO;
FavoritesViewController *faveView = [[FavoritesViewController alloc] initWithNibName:#"FavoritesView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:faveView animated:YES];
table.userInteractionEnabled = YES;
}
-(IBAction) sideNew:(id)sender{
CGRect frame = self.browseView.frame;
frame.origin.x = 0;
self.browseView.frame = frame;
menuOpen = NO;
NewCampgroundsViewController *theNewCampView = [[NewCampgroundsViewController alloc]
initWithNibName:#"NewCampgroundsView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:theNewCampView animated:YES];
table.userInteractionEnabled = YES;
}
-(IBAction) sideCancelled:(id)sender{
CGRect frame = self.browseView.frame;
frame.origin.x = 0;
self.browseView.frame = frame;
menuOpen = NO;
CancelledCampgroundsViewController *cancCampView = [[CancelledCampgroundsViewController alloc]
initWithNibName:#"CancelledCampgroundsView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:cancCampView animated:YES];
table.userInteractionEnabled = YES;
}
-(IBAction) sideCall:(id)sender{
NSLog(#"Calling Passport America...");
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:**********"]];
table.userInteractionEnabled = YES;
}
-(IBAction) sideEmail:(id)sender{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"mailto:***************"]];
table.userInteractionEnabled = YES;
}
-(void) searchBarSearchButtonClicked: (UISearchBar *)searchBar {
SearchViewController *search = [[SearchViewController alloc] initWithNibName:#"SearchViewController" bundle:[NSBundle mainBundle]];
NSString *searchText = [[NSString alloc] initWithString:mainSearchBar.text];
search.searchText = searchText;
[self dismissKeyboard];
[self.navigationController pushViewController:search animated:YES];
table.userInteractionEnabled = YES;
menuOpen = NO;
CGRect frame = self.browseView.frame;
frame.origin.x = 0;
self.browseView.frame = frame;
}
-(void) swipeLeft:(UISwipeGestureRecognizer *)recognizer {
if (!menuOpen) {
CGRect frame = self.browseView.frame;
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector( animationDidStop:finished:context: )];
[UIView beginAnimations:#"slideMenu" context:(__bridge void *)(self.browseView)];
frame.origin.x = -212;
menuOpen = YES;
self.browseView.frame = frame;
table.userInteractionEnabled = NO;
[UIView commitAnimations];
} else {
//menu already open, do nothing
}
}
-(void) swipeRight:(UISwipeGestureRecognizer *)recognizer {
if (!menuOpen) {
//menu closed, do nothing
} else {
CGRect frame = self.browseView.frame;
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector( animationDidStop:finished:context: )];
[UIView beginAnimations:#"slideMenu" context:(__bridge void *)(self.browseView)];
frame.origin.x = 0;
menuOpen = NO;
self.browseView.frame = frame;
table.userInteractionEnabled = YES;
[UIView commitAnimations];
}
}
- (void) viewWillDisappear:(BOOL)animated {
[self.table deselectRowAtIndexPath:[self.table indexPathForSelectedRow] animated:animated];
[super viewWillDisappear:animated];
}
- (void)didReceiveMemoryWarning {
NSLog(#"Memory Warning!");
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.
}
- (void)viewDidUnload {
self.table = nil;
self.countriesArray = nil;
self.browseView = nil;
[super viewDidUnload];
}
#end
Determine which cell the swipe takes place in, compute the index path, and call didSelectRowAtIndexPath from your gestureRecognizer code.