popOver table view - iphone

In my project , On clicking the button the string present in the button Action method should store in popover table view cell.
I cam able to store a single sting , to the first cell ....
And now my problem is i had Four buttons each button action consists of 4 strings , and now the should at a time to the popover table view ,,,
#import "SecondDetailViewController.h"
-(IBAction)viewButtonPressed:(id)sender
{
[super viewDidUnload];
//create the view controller from nib
self.tablePopoverController = [[[TablePopoverController alloc]
initWithNibName:#"TablePopover"
bundle:[NSBundle mainBundle]] autorelease];
////-------------------------------
myArray = [[NSMutableArray alloc] initinitWithObjects:myString,myString2,myString3,myString4,myString5,myString6,nil];
tablePopoverController.getingOrder = myArray ;
NSLog(#"table popo %#",myArray);
tablePopoverController.contentSizeForViewInPopover = CGSizeMake(250, 250);
//create a popover controller
self.popoverController = [[[UIPopoverController alloc]
initWithContentViewController:tablePopoverController] autorelease];
//present the popover view non-modal with a
//refrence to the button pressed within the current view
[popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
-(IBAction)orderButtonPressed
{
myString = staterlable1.text;
[myArray addObject:myString];
NSLog(#"myArray%#",myString);
}
-(IBAction)orderButton2Pressed
{
myString2 = staterlable2.text;
NSLog(#"myArray%#",myString2);
[myArray addObject:myString2];
}
-(IBAction)orderButton3Pressed
{
myString3 = staterlable3.text;
[myArray addObject:myString3];
NSLog(#"myArray%#",myString3);
}
-(IBAction)orderButton4Pressed
{
myString4 = staterlable4.text;
[myArray addObject:myString4];
NSLog(#"myArray%#",myString4);
}
-(IBAction)orderButton5Pressed
{
myString5 = staterlable5.text;
[myArray addObject:myString5];
NSLog(#"myArray%#",myString5);
}
-(IBAction)orderButton6Pressed
{
myString6 = staterlable6.text;
[myArray addObject:myString6];
NSLog(#"myArray%#",myString6);
my Problem Is after clicking these buttons the myString1 - to - myString6 NSString objects Should Store into NSMutableArray so That i will display all the strings in the TableViewPopOverController which will popover when clicking the another button in the second detailViewController........
thanks in Advance......

The usual way to do this is to embed TablePopoverController in a UINavigationController. Then, in TablePopoverController when handling tableView:tableView didSelectRowAtIndexPath:indexPath push detailViewController into the UINavigationController.
For example, you could build Controller structure the following way (based on your example):
//create a popover controller
self.popoverController = [[[UIPopoverController alloc] initWithContentViewController:[[[UINavigationController alloc] initWithRootViewController:initWithContentViewController:tablePopoverController] autorelease]] autorelease];
It is similar to your popover-creation code, put inserts a UINavigationController under the popover. Now, in TablePopoverController you should handle row selections the usual way with a UINavigationController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
DetaiViewController *detail = [[DetaiViewController alloc] init];
/* Configure detail using indexpath here indexPath
...
*/
[self.navigationController pushViewController:detail animated:YES];
}
This will work as expected (by pushing the new view into the UINavigationController) because we set controller structure with a UINavigationController.

Related

iOS. addsubview to master-detail app

I have a master-detail application with news. It works. In detail controller i used UIWebView.
I created comments-class with xib and am trying to add it to my detail view.
Comments are UITableViewController.
After that i can see only comments, not detail-text.
I tried to scroll my webview and there is no text. But in detailviewController i did NSLog for my text and saw it. If i set newsTextHeight to 480 i see an empty view.
What am I doing wrong?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat newsTextHeight = 250;
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
CommentsViewController *commentController = [[CommentsViewController alloc] init];
NewsItem *newsItem = [news objectAtIndex:indexPath.row];
detailViewController.description = newsItem.description;
detailViewController.title = newsItem.date;
commentController.news_id = newsItem.news_id;
detailViewController.news_id = [newsItem.news_id intValue];
int views = [newsItem.viewsCnt intValue];
views++;
NSString *strFromInt = [NSString stringWithFormat:#"%d",views];
newsItem.viewsCnt = strFromInt;
[self.tableView reloadData];
//[self.navigationController presentedViewController];
[self.navigationController pushViewController:detailViewController animated:YES];
detailViewController.navigationController.toolbarHidden = NO;
[detailViewController addChildViewController:commentController];
[commentController didMoveToParentViewController:detailViewController];
[detailViewController.view addSubview:commentController.view];
detailViewController.view.frame = CGRectMake(0, 0, detailViewController.view.bounds.size.width, newsTextHeight);
commentController.tableView.contentInset = UIEdgeInsetsMake(detailViewController.view.frame.size.height, 0, 0, 0);
[commentController release];
[detailViewController release];
}
results: http://s18.postimg.org/5cv8ftbbd/detail.png
What Kiattisak is getting at is that the problem can be that your view detailViewController.view.frame is using autolayout. And therefor won't be able to be resized programmatically. (This is if you are not using storyboards)
In InterfaceBuilder, highlight your view:
And untick the Use Autolayout box in the first tab of the attributes inspector.
Hope it helps.

Populate Table With Help of PopOverController - Objective C

I am using a UIButton, on clicking it I want to display the contents that are present in my NSMutableArray in UITableView with the help of UIPopOverController i.e. I want a UITableView to pop up whose cells show the contents of my NSMutableArray.
I am using the following lines of code:
UITableViewController *table= [[UITableViewController alloc]init];
table.delegate = self;
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:table];
self.popoverController = popover;
popoverController.delegate = self;
NSString *hDir = [NSHomeDirectory() stringByAppendingPathComponent:#"Documents"];
NSString *hFilePath = [hisDir stringByAppendingPathComponent:#"hhhh.txt"];
NSArray *array = [NSArray arrayWithContentsOfFile:hFilePath ];
NSMutableArray *kkkk = [[NSMutableArray alloc] init];
for (NSDictionary *dict in array) {
[kkkk addObjectsFromArray:[dict allKeys]];
}
table = [[UIImageView alloc] initWithFrame:[window bounds]];
// Set up the image view and add it to the view but make it hidden
[window addSubview:table];
table.hidden = YES;
[window makeKeyAndVisible];
I am unable to get the UITableView to pop up on the press of my UIButton. Can anyone help me to sort it out?
One way to show the UITableView in the UIPopOverController is by creating a new UIViewController class. And invoking it in initWithContentViewController method of UIPopOverController.
1. Create a new UIViewController or UITableViewController class. Create an instance of it.
2. Use the instance in the initWithContentViewController method of UIPopOverController.
3. Mention from where it should "pop"
For Example in your Button action :
-(IBAction)yourButtonAction:(id)sender
{
YourNewViewController*newVC=[[YourNewViewController alloc]init];
UIPopoverController*somePopOver=[[UIPopoverController alloc]initWithContentViewController:catergoryVC]; //Tell which view controller should be shown
[somePopOver setPopoverContentSize:CGSizeMake(200, 200)]; // set content size of popover
[somePopOver presentPopoverFromRect:yourButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; //From where it should "pop"
}
It seems you want to present it from a UIBarButtonItem so instead of presentPopoverFromRect use presentPopoverFromBarButtonItem
[somePopOver presentPopoverFromBarButtonItem:yourBarButtonItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
If you want to display popover on press of button click, then first add your button in viewcontroller, display that view controller as follows:
In app delegate write code:
MyViewController *viewController = [[MyViewController alloc] init];
[self.window addSubView:viewController.view];
In MyViewController add button and provide target to that button displayPopup as follows:
-(void)displayPopup:(id)sender
{
UITableViewController *tblViewPopover = [[UITableViewController alloc] init];
tblViewPopover.tableView.delegate = self;
tblViewPopover.tableView.dataSource = self;
tblViewPopover.tableView.backgroundColor = [UIColor whiteColor];
tblViewPopover.tableView.separatorStyle= UITableViewCellSeparatorStyleSingleLine;
float theWidth = 280;
tblViewPopover.contentSizeForViewInPopover = CGSizeMake(theWidth,200);
if(m_popOvrController){
[m_popOvrController dismissPopoverAnimated:NO];
[m_popOvrController release];
m_popOvrController=nil;
}
m_popOvrController = [[UIPopoverController alloc] initWithContentViewController:tblViewPopover];
[tblViewPopover release];
[m_popOvrController presentPopoverFromRect:sender.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];
}
and you can use tableview delegate methods to display data in tableview.
I think, UIPopoverViewController is initialized using UIViewController and here you are using UIView(UITableView).
Can you please try using UITableViewController instead?
Also, if things does not work according to plan when you create it using the code try using an XIB explicitely.
This should help.

Pushing UIViewController onto a UINavigationController

The other day I asked about using a UINavigationController as a child of a UIViewController. I got that working via the answer. Now what I'm trying to do is push a controller onto the nav stack. When a table cell is touched, I do the following:
- (void) showSetup {
NSLog(#"Showing Setup");
SetupViewController *controller = [[SetupViewController alloc]initWithNibName:#"SetupViewController" bundle:nil];
self.setupViewController = controller;
self.setupViewController.title = #"Setup";
[self.navigationController pushViewController:self.setupViewController animated:YES];
[controller release];
}
I can see the log statement in my console, but the view never changes. Am I missing something?
Hmmm, well it's a bit tricky without knowing the details of your implementation -- I assumed that you implemented your navigation controller as in the linked article. Also although you give no details it sounds like you've added a table view controller somewhere along the line, so I made the UIViewController conform to the UITableView protocols to handle everything in one place:
#interface SOViewController : UIViewController<UITableViewDelegate,UITableViewDataSource > {
UINavigationController* navController;
}
- (IBAction) pushMe:(id)sender;
#end
I dropped a button on the SOViewController's view in IB and wired the pushMe: action to it. I also created another UIViewController-based class called JunkController and dropped a "Junk" label on it's view in IB -- that's all I did in IB. In the SOViewController's viewDidLoad:
navController = [[[UINavigationController alloc] init] retain];
navController.navigationBar.barStyle = UIBarStyleBlackOpaque;
navController.toolbarHidden = YES;
UITableViewController* tvController = [[UITableViewController alloc] init];
UITableView* tv = [[UITableView alloc] init];
tvController.tableView = tv;
tv.delegate = self;
tv.dataSource = self;
[navController setViewControllers:[NSArray arrayWithObject:tvController]];
In the pushMe: action implementation:
[self presentModalViewController:navController animated:YES];
Implemented the tableView delegate and datasource methods; for selection:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"row selected");
JunkController* junk = [[JunkController alloc] initWithNibName:#"junkcontroller" bundle:nil];
[navController pushViewController:junk animated:YES];
[junk release];
}
This should yield an app that surfaces a screen with a "Push me" button. When that button is pressed you should get an animated modal navigation-based table view -- mine had one row in it that contained a label "select me". Touching this row should animate the junk controller into view.
There is no need to make setupViewController a declared property in this view controller. Also, I could be mistaken but I thought "controller" was a reserved name in Cocoa, I'd change that name. So make sure you have registered with the UITableViewDelegate and use - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath to hook into and push your new view controller as follows:
SetupViewController *detailViewController = [[SetupViewController alloc] initWithNibName:#"SetupViewController" bundle:nil];
detailViewController.title = #"Setup";
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
Goodluck!

TableView help pushing a custom view

So I am trying to simple traverse to the next level of a table view by doing this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 1) {
FiltersController *aFiltersCont = [[FiltersController alloc] init];
aFiltersCont.displayedFilters = [appDelegate.groupedBusiness allKeys];
aFiltersCont.currentLevel = self.currentLevel + 1;
[self.navigationController pushViewController:self animated:YES];
}
}
is there any reason why this would not be pushing the controller? I had a similar problem before, but solved it by displaying the view modally. However, this time, this is in a popover and needs to slide to the next screen inside that popover. Any Ideas? Thanks in advance.
OK I am going to put some more source up here to try and help...
Inside the main view controller I have this code to make the popover from a button:
// Create and configure the filters controller.
FiltersController *aFiltersController = [[FiltersController alloc] initWithStyle:UITableViewStylePlain];
self.filtersController = aFiltersController;
filtersController.appDelegate = self.appDelegate;
UINavigationController *filtersNavController = [[UINavigationController alloc] initWithRootViewController:filtersController];
UIPopoverController *filtersPopover = [[UIPopoverController alloc] initWithContentViewController:filtersNavController];
self.filtersPopoverController = filtersPopover;
filtersPopoverController.delegate = self;
and then I have the code I first posted in my filtersController class. Does that help at all?
[self.navigationController pushViewController:self animated:YES];
Should be
[self.navigationController pushViewController:aFiltersCont animated:YES];
If you are just displaying your sublcass of UITableViewController inside a UIPopoverController, the UINavigationController will not be created for you automatically. You may need to modify the code where you are creating the UIPopoverController with something like this:
MyTableViewController *table = [[[MYTableViewController alloc] init] autorelease];
UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:table] autorelease];
myPopover = [[UIPopoverController alloc] initWithContentViewController:nav];
Then you should be able to push and pop navigation controllers on the stack no problem.
you are pushing self which is a reference to the current view controller. you should change the line with the push to the following if aFiltersCont is the viewController you are trying to drill to.
[self.navigationController pushViewController:aFiltersCont animated:YES];
You might be confused about the index. The first index is 0 not 1, so maybe you want indexPath.row == 0?
Also, you should release aFiltersCont before returning (you're leaking a FiltersController and anything it owns every time you run this method.
So maybe this?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
FiltersController *aFiltersCont = [[[FiltersController alloc] init] autorelease];
aFiltersCont.displayedFilters = [appDelegate.groupedBusiness allKeys];
aFiltersCont.currentLevel = self.currentLevel + 1;
[self.navigationController pushViewController:aFiltersCont animated:YES];
}
}

pushing view controller inside a tab bar from app delegate, after a notification

i have an app with tab bar and a navigation controller inside every tab.
i have set a notification that when it lunches the user can get lunch the app by pressing the action on the alert.
i want to redirect the user to one of the views inside one of the controllers.
i have tried this:
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
NSArray *data = [notif.userInfo objectForKey:#"todoDate"];
NSInteger ind = [[data objectAtIndex:2] integerValue];
QuickViewController *detailViewController ;
detailViewController = [[QuickViewController alloc] initWithNibName:#"QuickViewController" bundle:nil];
detailViewController.title = #"Edit";
detailViewController.personName = [data objectAtIndex:0];
detailViewController.DelitionDate=[data objectAtIndex:1];
detailViewController.personCategory=#"NO Category";
detailViewController.personID = ind r ;
rootControler.selectedIndex = 1;
[rootControler.tabBarController.selectedViewController.navigationController pushViewController:detailViewController animated:YES];
}
but nothing is happening (no crashing) except of the :rootControler.selectedIndex = 1;
when i tried :
presentModalViewController
i got the view perfectly but without the navigation controller.
thanks
shani
It sounds like you're pushing detailViewController when you really want to push a UINavigationController with detailViewController as its root view. Try something like this:
QuickViewController *detailViewController ;
detailViewController =
[[QuickViewController alloc] initWithNibName:#"QuickViewController"
bundle:nil];
UINavigationController *navigationController =
[[UINavigationController alloc] initWithRootViewController:detailViewController];
[detailViewController release];
...
[rootControler.tabBarController.selectedViewController.navigationController
pushViewController:navigationController animated:YES]