populate uipopover with thumbs and text - iphone

I'm drawing a popover after a button clicked and I wish view into the popover a grid with a square thumb of an image and some text....
thanks!

If I understand your question right, you want to have a custom view in your UIPopovercontroller. This can be done by creating a new UIViewController, with its own content.
Then load you popovercontroller from the class you load the action from. Example:
myView *theView = [[myView alloc] initWithNibName:#"myView"
bundle:nil];
UIPopoverController* aPopover = [[UIPopoverController alloc] initWithContentViewController:theView];
[aPopover setDelegate:self];
[aPopover setPopoverContentSize:CGSizeMake(320, 320) animated:YES];
[theView setPopover:aPopover];
[theView release];
[self.popoverController presentPopoverFromRect:CGRectMake(510,370,0,0) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

Related

Nav Bar button loading random view before loading appropriate view

I have a back button on my answer view controller (a view controller that displays answers) if the user hits the back button I created it switches to a view that has the title of "Back" and just an empty tableview, before switching back to my main view of where all the questions to be answered are displayed. Why is this happening? Its a very brief thing, but definitely noticeable!
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 48)];
navBar.delegate = self;
UINavigationItem *backItem = [[UINavigationItem alloc] initWithTitle:#"Back"];
[navBar pushNavigationItem:backItem animated:NO];
UINavigationItem *topItem = [[UINavigationItem alloc] initWithTitle:#"Question"];
[navBar pushNavigationItem:topItem animated:NO];
topItem.leftBarButtonItem = nil;
[self.view addSubview:navBar];
- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item
{
ViewController *controller = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:controller animated:YES completion:nil];
return true;
}
- (void)navigationBar:(UINavigationBar *)navigationBar didPopItem:(UINavigationItem *)item
{
ViewController *controller = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:controller animated:YES completion:nil];
}
You're creating your own UINavigationBar and UINavigationItem instances and you probably shouldn't be. The situation you describe is exactly what a UINavigationController is for. When using a UINavigationController it creates the UINavigationBar and each UIViewController that you show on screen (push into the navigation controller) has its own UINavigationItem (with the title taken from the title of the view controller).
The reason you get an empty 'view' titled "Back" is that you're creating it:
UINavigationItem *backItem = [[UINavigationItem alloc] initWithTitle:#"Back"];
[navBar pushNavigationItem:backItem animated:NO];
Dispense with all of this, create a UINavigationController and make your question view controller it's root view controller, then add the navigation controller to the screen. Then when a question is answered, push the answer view controller:
[self.navigationController pushViewController:answerViewController animated:YES];

Add a UITabbarControler in UIScrollView in iphone?

I have made a UIScrollView inside a UIViewController .and now I want to add a UITabBarController to it .But when I do it ,I couldnot see the TabBarController added to it..
I have written this code
[testscroll setScrollEnabled:YES];
[testscroll setContentSize:CGSizeMake(320,800)];
FirstViewController *first = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
first.title=#"Search";
UserProfile *second=[[UserProfile alloc]initWithNibName:#"UserProfile" bundle:nil];
second.title=#"My Profile";
UserActivities *third=[[UserActivities alloc]initWithNibName:#"UserActivities" bundle:nil];
third.title=#"My Activities";
LogOut *logout=[[LogOut alloc]initWithNibName:#"LogOut" bundle:nil];
logout.title=#"Sign Out";
NSArray *viewArray= [NSArray arrayWithObjects:first,second,third,logout, nil];
tabBarController=[[UITabBarController alloc] init];
[tabBarController setViewControllers:viewArray animated:NO];
[self presentModalViewController:tabBarController animated:NO];
I have added this in a fifthViewController.I can see the UIScrollView and some Labels and textFields added but not the TabBarController added.Wher i m going wrong ..?
As far as I can see, you are creating a tab bar controller and then presenting it modally:
NSArray *viewArray= [NSArray arrayWithObjects:first,second,third,logout, nil];
tabBarController=[[UITabBarController alloc] init];
[tabBarController setViewControllers:viewArray animated:NO];
[self presentModalViewController:tabBarController animated:NO];
It does not appear in scrollView because you are not "connecting" the two in any ways.
If you want your tab bar controller to appear inside of the scroll view, add it as a subview to the latter:
[testscroll setScrollEnabled:YES];
[testscroll setContentSize:CGSizeMake(320,800)];
...
[testscroll addSubview:tabBarController.view];
(I assume that tabBarController is a property and that the scroll view is displayed in some way)

navigation bar in popover

having problem with my navigation bar, when I present it via popover, my nav bar was hidden,
like this:
which should be this:
my code:
self.popoverController =
[[UIPopoverController alloc] initWithContentViewController:imagePickerController];
popoverController.delegate = self;
CGRect popoverRect = [self.view convertRect:[tsuikaButton frame]
fromView:[tsuikaButton superview]];
popoverRect.size.width = MIN(popoverRect.size.width, 100);
[self.popoverController
presentPopoverFromRect:popoverRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
[popoverController setPopoverContentSize:CGSizeMake(1024, 500)];
Thanks for the help.
Are you trying to make the imagePickerController take up the whole screen? If so, have you thought of just pushing it and not using a popover controller?

Add UIToolbar to UIViewController

How to add UIToolbar to the below UIViewController.
PageOneViewController *viewController = [[PageOneViewController alloc] init];
[self presentModalViewController:viewController animated:YES];
[viewController release];
This UIViewController is the view of the mainviewcontroller and UIToolbar is in the mainviewcontroller. So basically when this view is loaded i want UIToolbar to load as well.
Can someone give me an idea
Just add the UIToolbar as a subview of the PageOneViewController:
UIToolbar *toolbar = [[UIToolbar alloc] init];
[viewController addSubview:toolbar];
[toolbar release];
toolbar.frame = // Set this to position the toolbar correctly
[self presentModalViewController:viewController animated:YES];

Problem in showing subview as popover

I want to show the subview of a view in popover.
To elaborate,
I have a mainViewController.
I hava a subview 'songListView' in this mainViewController.
I have a button titled 'list' in the mainViewController' itself.
I want to show the songListView in popover on clicking the button 'list'.
So, how should I do this.
You could use the below code as a reference for showing PopOver from a UIButton
-(void) buttonAction:(id)sender {
//build our custom popover view
UIViewController* popoverContent = [[UIViewController alloc]
init];
UIView* popoverView = [[UIView alloc]
initWithFrame:CGRectMake(0, 0, 200, 300)];
popoverView.backgroundColor = [UIColor greenColor];
popoverContent.view = popoverView;
//resize the popover view shown
//in the current view to the view's size
popoverContent.contentSizeForViewInPopover =
CGSizeMake(200, 300);
//create a popover controller
self.popoverController = [[UIPopoverController alloc]
initWithContentViewController:popoverContent];
//present the popover view non-modal with a
//refrence to the button pressed within the current view
[self.popoverController presentPopoverFromRect:popoverButton.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
//release the popover content
[popoverView release];
[popoverContent release];
}
My problem is solved.
I just created another View Controller class, i.e. 'TempPopoverView'.
Then I set the view of this TempPopoverView equal to the subview of my MainView
Here is the code snippet from my code:
TempPopoverView *viewController = [[TempPopoverView alloc]initWithNibName:#"TempPopoverView" bundle:nil];
[self. songListView setHidden:NO];//songListView is subview of MainView
viewController.view=self. songListView;
UINavigationController *navCont = [[UINavigationController alloc]initWithRootViewController:viewController];
navCont.navigationBar.tintColor = [UIColor colorWithRed:.102 green:.102 blue:.102 alpha:1];
[self showPopOverController:navCont andFrame:sender.frame andInView:self.view];//self.view is the MainView
[viewController release];
[navCont release];
U can use presentModalViewController on your main view.
For example
SongListView *songList = [[SongListView alloc] init];
[self presentModalViewController: songList animated: YES];
There are different animations possible as well.
as simple as you think to add subview in self.view
[popoverController.contentViewController.view addSubview:yourselfobject];