how to display popover click on a tableview cell in ipad - objective-c

i am using a TableView in my application where i want a Pop over View when i clicked on a tabel cell, all the content which is in table Cell should display in a pop over view so plz suggest me how to do??
i have some sample code below which is not working..so suggest with code i want all the content in the cell to displayed in the pop over view.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIView *aView = [[UIView alloc] init];
UIPopoverController *popoverController = [[UIPopoverController alloc]
initWithContentViewController:aView];
popoverController.popoverContentSize = CGSizeMake(320, 416);
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[popoverController presentPopoverFromRect:cell.bounds inView:cell.contentView
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

The UIPopoverController class reference clearly states
To display a popover, create an instance of this class and present it
using one of the appropriate methods. When initializing an instance of
this class, you must provide the view controller that provides the
content for the popover. Popovers normally derive their size from the
view controller they present
Your popoverController should have a view controller and not a view.
YourViewController *aViewController = [[YourViewController alloc] initWithNibName:nibName bundle:nil];
UIPopoverController *popoverController = [[UIPopoverController alloc]
initWithContentViewController:aViewController];
Then you can present this pop over

Your code is fine, but
You should have UIViewController instead UIView.

you have to pass the view controller instead of view

Related

Switch to another ViewController by selecting Cell of programmatically created collectionView

I've got a CollectionView which was programmatically created, now I want to switch to another CollectionView by selecting one of its Cells. Heres my code so far, but nothing happens:
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath*)indexPath{
NSLog(#"Cell selected");
DetailCell *detailCell = [[DetailCell alloc] init];
[self.navigationController pushViewController:detailCell animated:YES];
}
Console says "Cell selected", so the CollectionView recognizes my touch, but the app won't switch to the other view. I've created a ViewController with the custom Class "DetailCell".
I'd check and make sure your self.navigationController isn't nil.
I just solved this problem :
mainView .m
cView = [[CollectionView alloc]init];
cView.view.frame = CGRectMake(0, 0, 320, 436);
cView.nav = self.navigationController;
[_contentScrollView addSubview:cView.view];
CollectionView.h
#property (nonatomic,weak) UINavigationController *nav;
CollectionView.m
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath*)indexPath{
DetailCell *detailCell = [[DetailCell alloc] initWithDetails:_pageCategorie and: indexPath];
[_nav pushViewController:detailCell animated:YES];
}

Push a string and display in a UITextField

I am doing a small app and I am using a UISplitVIewController and I am trying to push the UITable cell text to the detail view and display it in a UITextField. I have managed to push the string nicely when i test it with a NSLog but when i apply to the UITextField it does not display not sure why here my method: (I am doing this using a storyboard)
-(void)pushModuleName:(NSString*)moduleName
{
self.Lv4ModuleTitleTextField.text = moduleName;
NSLog(#"name pushed%#",moduleName);
}
Not sure why this doesn't work.
[UPDATE]
UITableViewController.m (where the method is called)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *selectedModule = [NSString stringWithFormat:#"%#",[_numberOfRows objectAtIndex:indexPath.row]];
Lv4GradeViewController *lv4 = [[Lv4GradeViewController alloc] initWithNibName:nil bundle:nil];
[lv4 pushModuleName:selectedModule];
}
You are creating a new instance of Lv4GradeViewController with the following code but no XIB file which will contain the text field:
Lv4GradeViewController *lv4 = [[Lv4GradeViewController alloc] initWithNibName:nil bundle:nil];
I would suggest you instantiate Lv4GradeViewController with the storyboard instantiateViewControllerWithIdentifier method:
Lv4GradeViewController *lv4 = [self.storyboard instantiateViewControllerWithIdentifier:#"IdentifierName"];
And remember to set the storyboard ID of the Lv4GradeViewController the same as IdentifierName in the storyboard.
The problem is that you're not getting a reference to the Lv4GradeViewController that you have on screen, you're creating a new one with alloc init. A split view controller, has a viewControllers array, with the controller at index 0 being the master controller, and the one at index 1 being the detail controller. So, the didSelectRowAtIndexPath method should look like this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *selectedModule = [NSString stringWithFormat:#"%#",[_numberOfRows objectAtIndex:indexPath.row]];
Lv4GradeViewController *lv4 = self.splitViewController.viewControllers[1];
[lv4 pushModuleName:selectedModule];
}

Storyboards: Open UIViewController from storyboard as popover from image in UITableViewCell

I have a Custom UITableViewCell class and the custom cell has an image button in it that is linked back to a method on the cell class. When this method is triggered, I want to launch an orphaned UIViewController from the storyboard inside a popover. I've tried several techniques for doing this. Interface Builder will not compile if I add the UIViewController as a segue from the button on the prototype cell. Does anyone have any suggestions?
UPDATE: I Got it working with the following:
UITableView *tv = (UITableView *) self.superview;
UITableViewController *vc = (UITableViewController *) tv.dataSource;
UIStoryboard *storyboard = vc.storyboard;
UIViewController *actionView = [storyboard
instantiateViewControllerWithIdentifier:#"ActionView"];
popoverController = [[UIPopoverController alloc]
initWithContentViewController:actionView];
popoverController.popoverContentSize = CGSizeMake(320, 416);
[popoverController presentPopoverFromRect:self.actionButton.bounds
inView:self.actionButton
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
You should be able to use instantiateViewControllerWithIdentifier: from UIStoryboard to pick up any view controller if you have it identified correctly. (Since the easiest way to get a reference to the storyboard is from some view controller that already came from it, you may want to have the cell notify the current controller to do this...that depends on how your objects are connected.)

NewView showing in PopOver instead of newView

I have the right view selected from my PopOver but instead of showing in Parent View it is showing in PopOverView.
Here are some screenshots:
After I select the Feedback option instead showing the view in my parentview which in my case is SecondViewController (grey background screen) it is showing in the PopOver itself.
For information I have Three VC's namely FirstViewController, SecondViewController and ThirdViewController each assigned to each TabBar item. I want to make SecondViewController as parent for the PopOver.
Here is my code where I create PopOver in my AppDelegate.m
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if([viewController isKindOfClass:[SecondViewController class]]){
NSInteger index = [[self tabBarController] selectedIndex];
CGRect buttonFrame = [[[[[self tabBarController] tabBar] subviews] objectAtIndex:index+1] frame];
PopOverViewController *popoverContentController = [[PopOverViewController alloc]init];
UINavigationController *navcon = [[UINavigationController alloc]initWithRootViewController:popoverContentController];
popoverContentController.contentSizeForViewInPopover = CGSizeMake(250, 85);
popover = [[UIPopoverController alloc]initWithContentViewController:navcon];
NSLog(#"X:%f Y:%f",buttonFrame.origin.x,buttonFrame.origin.y);
[popover presentPopoverFromRect:buttonFrame inView:self.tabBarController.tabBar permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
}
And the code in my PopOverController.m where I am making a choice of which new view to show
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
sendFeedback *sendEmailViewController = [[sendFeedback alloc]initWithNibName:#"sendFeedback" bundle:nil];
downLoad *downloadFilelViewController = [[downLoad alloc]initWithNibName:#"downLoad" bundle:nil];
if (indexPath.row == 0)
[self.navigationController pushViewController:sendEmailViewController animated:YES];
else
[self.navigationController pushViewController:downloadFilelViewController animated:YES];
}
Can anyone let me know how I can make the reference to my parent view (SecondViewcontroller) so that the new view shows in my parent view rather than the popover view.
Thanks
You insert into popover UINavigationController and in didSelectRowAtIndexPath push newly created controller to existed stack (into popover UINavigationController), but not into tab bar.
In order to push newly created controller to second tab you need to assign second tab (now it is SecondViewController) to new UINavigationController and use exactly this navigation stack.
Code will look like this:
UINavigationController *navController = (UINavigationController*)[tabBarController.viewControllers objectAtIndex:1];
[navController pushViewController:downloadFilelViewController animated:YES];

Accessing UITableViewController > UIView > UIView?

Can anyone tell me if this is possible?
I have a setup a UITableViewController which consists of a number of cells, if you select one of these cells you are taken to a new viewController using pushViewController (see below)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
NSLog(#"CELL__: You tapped the row ... %#", [list objectAtIndex:row]);
TestController *testController = [[TestController alloc] init];
[[self navigationController] pushViewController:testController animated:YES];
[testController release];
}
If in the implementation for "TestController" I would like to refer back to [self navigationController] (or maybe to add yet another view) is there any way to do that. My problem is that I need to access [self navigationController] to push further views and I don't know how to do that from the bottom controller?
Does that make sense?
Gary
From within TestController you reference the same UINavigationController via [self navigationController] as well.
EDIT to elaborate after comment:
The navigationController property is a property of UIViewController. If the controller is contained within a UINavigationController then it's own navigationController property will be a reference to that container UINavigationController. The same applies for tabBarController and splitViewController.