presentModalViewController Problem ! - iphone

So,
I have a form (which is basically a UITableView), and once I finish the form, I click the 'Done' button which is on top of the screen.
After clicking, I need to add the data to another tableView (which is in another tableViewController). This table is also inside a Navigation Controller.
After I press the Done Button, I need the presentModalViewController to be the new TableView (with the new data) along with the Navigation Controller on top of the tableView.
So, to summarize:
The Done Button is in someTableViewController.
I need to add an object (lets just say I am adding a a name called "Dobby" for simplicity) into another tableView called dogTableViewController.
I reload the data , and present the screen which has dogTableViewController inside the dogNavigationController.
All the classes are referenced properly and included.
I am pasting the -(IBAction) when the Done Button is clicked.
-(IBAction) doneWithData: (UIBarButtonItem*) sender{
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[indicator sizeToFit];
indicator.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin);
indicator.tag = 1;
[self.view addSubview:indicator];
[indicator setBackgroundColor:[UIColor clearColor]];
indicator.center = self.view.center;
indicator.hidden = FALSE;
[indicator startAnimating];
if (self.dogTableViewController == nil)
{
DogTableViewController *temp = [[DogTableViewController alloc] init];
self.dogTableViewController = temp;
[temp release];
}
if (self.dogNavigationController == nil)
{
DogNavigationController *temp = [[DogNavigationController alloc] init];
self.dogNavigationController = temp;
[temp release];
}
[self.dogTableViewController.dogArray addObject:#"Dobby"];
[self.dogTableViewController.tableView reloadData];
NSLog (#"%#", [self.dogTableViewController.dogArray objectAtIndex:0]);
//Prints out "Null" //
[self presentModalViewController:dogNavigationController animated:YES];
[indicator release];
}
When I do all this and Click the Done button,
I get an empty Navigation Screen with NO TABLE in it. Plus I also had some buttons on the dogNavigationController screen. Nothings visible !!
My objective is to just transfer the screen to this new screen (which happens to be a home screen, and not the rootController). Do you think I should go with the modalViewController for this task ? Do you think I should use some other way to transfer data to another screen ?
p.s. I do not want to use PushViewController.

I think you should do
[self.navigationController popToRootViewControllerAnimated:YES];
rather. To get the root view controller, you can do,
DogTableViewController * viewController = [self.navigationController.viewControllers objectAtIndex:0];
[viewController.dogArray addObject:aDog];
Original Answer
Shouldn't you be initializing a navigation controller with the root view controller?
DogNavigationController *temp = [[DogNavigationController alloc] initWithRootViewController:self.dogTableViewController];

Related

Pushing and Popping View Controllers

I have a navigation view controller which is a table view and then from the table view if i select a row it goes into detail view page. When i go to the detail view page i retrieve some information from the server and if the server does not respond then i get an alert view pop up which appears in front of my parent navigation view. now when press ok on the alert view and click on another row and it does go into my "didselectview" method but does not go to my detail view page. Would anyone know why? Code given below.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//Navigation logic may go here. Create and push another view controller.
Item *selectedItem = (Item *)[self.fetchedObjectsArray objectAtIndex:indexPath.row];
NSString * urlString = [CONST_FEED_DISCRIPTION_URL stringByAppendingString:selectedItem.guid];
NSDate * dateString = selectedItem.date;
JsonViewController *jsonViewController = [[JsonViewController alloc] initWithURLString:urlString date:dateString];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"Back"
style:UIBarButtonItemStyleBordered
target:nil
action:nil];
self.navigationItem.backBarButtonItem = backButton;
self.navigationController.navigationBar.tintColor = [UIColor colorWithHexString:CONST_NAVIGATIONBAR_COLOR];
[self.navigationController pushViewController:jsonViewController animated:YES];
[backButton release];
[jsonViewController release];
}
The first time around you get the alert view (which is an error message). After that nothing happens when u click on a row. but i know it goes into the method given below. would anyone know why? Does it have something to do with me pushing views? and not popping them?
Defer the push until the next runLoop, to let the tableView return:
dispatch_async(dispatch_get_main_queue(), ^ {
NSLog(#"Going to push...");
NSLog(#"...view Controller %#", jsonViewController);
[self.navigationController pushViewController:jsonViewController animated:YES];
[jsonViewController release];
NSLog(#"Just pushed %#", jsonViewController);
) );
Just to be clear, remove both these lines from the existing code:
[self.navigationController pushViewController:jsonViewController animated:YES];
[jsonViewController release];

UIPopOverController issue

I am trying to display tableviewcontroller in a popover from a barbuttonitem like this :
- (IBAction)sortData:(id)sender {
if(!sortViewController)
sortViewController = [[SortDataViewController alloc] init];
[sortViewController.tableView setDelegate:self];
[sortViewController.tableView setTag:12];
[sortViewController setIsMatter:YES];
sortViewController.contentSizeForViewInPopover = CGSizeMake(150, 100);
sortViewController._radioSelection = 0;
[sortViewController.tableView reloadData];
}
if(!popOverController) {
popOverController = [[UIPopoverController alloc] initWithContentViewController:sortViewController];
}
[popOverController setPopoverContentSize:CGSizeMake(100, 100)];
[popOverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
for the first time it got displayed for 1sec and automatically dismissed and from next time onwards it is not displaying at all. Can anyone please help me in this regard.
Set delegate for the UIPopOVerController...
popOverController.delegate = self;
I am reloading the view after each second to test some requirement and forgot to disable it. So my view is reloading continuously and it's not giving enough time for popover to display it's view. Now I disabled it and the popover is working without any issues.

How to use the navigation bar back button when using a viewbased app?

I have looked at several tutorials and different posts and can't seem to figure this out. I am simply trying to create a back button to take me back to a view where I was before. In the IB I create the button and link it to my backButton method. However, when I try to use it in the App I can't get it to work. Do I have to push it on the stack first? Any suggestions?
-(void)backButton:(id)sender{
[self.navigationController popViewControllerAnimated:YES];
}
Here is the code where I navigate from one view into another: Map is a view I use.
- (void) buttonClicked:(id)sender
{
UIButton *selectedButton = (UIButton *)sender;
int tempButtonTag = selectedButton.tag;
Map *map =[[Map alloc] initWithNibName:nil bundle:nil];
NSMutableString *tempID = [buttonIDArray objectAtIndex:tempButtonTag];
NSMutableString *tempType = [buttonTypeArray objectAtIndex:tempButtonTag];
[map setXmlID:tempID];
[map setXmlType:tempType];
buttonIDArray = nil;
buttonTypeArray = nil;
[buttonIDArray release];
[buttonTypeArray release];
[self presentModalViewController:map animated:YES];
}
The opposite of presentModalViewController is dismissModalViewController.
The opposite of pushViewController is popViewController.
You are mixing these up...

popViewControllerAnimated doesn't update info iPhone SDK

When I try to pop a view controller, it doesnt update info for the previous view. Example: I have a cell that displays text in a label in View1. When you click on the cell it goes to View2 (for example) When I choose an option in View2, popViewControllerAnimated is used to go back to View1, however, I want the label to now be updated with the new option in View1.
My dilemma is that when I pop View2, the label in View1 does not update. Any ideas? I've tried adding a [view1 reloadData]; before the view pops, but no luck.
//VIEW1 the cell that displays the label.
ringLabel = [[UILabel alloc] initWithFrame: CGRectMake(25, 12.7f, 250, 20)];
ringLabel.adjustsFontSizeToFitWidth = YES;
ringLabel.textColor = [UIColor blackColor];
ringLabel.font = [UIFont systemFontOfSize:17.0];
ringLabel.backgroundColor = [UIColor clearColor];
ringLabel.textAlignment = UITextAlignmentLeft;
ringLabel.tag = 0;
ringLabel.text = [plistDict objectForKey:#"MYOPTION"];
[ringLabel setEnabled:YES];
[cell addSubview: ringLabel];
[ringLabel release];
//VIEW2 when cell clicked
CustomProfileViewController *cpvc = [CustomProfileViewController alloc];
cpvc.ringtone = [ringList objectAtIndex:indexPath.row];
[cpvc.tblCustomTable reloadData];
[self.navigationController popViewControllerAnimated:YES];
You'll want to override -viewWillAppear: on the first view controller and update the label there. (Make sure to also call super).
Example:
- (void)viewWillAppear:(BOOL)animated {
// This method is called whenever the view is going to appear onscreen.
// (this includes the first time it appears.)
ringLabel.text = [plistDict objectForKey:#"MYOPTION"];
[super viewWillAppear:animated];
}
What is your plistDict object? How you initialize it? Are you sure, that it contains right value for your #"MYOPTION" key after the second view hides? As I can see, plistDict is an object inside your first viewController. Also I cannot see any sense in the last 4 lines of your code. They cause not reloading data but memory leak.
make sure you aren't losing anything important in your dealloc method. that messed me up for weeks. i was freeing a variable that pointed to the one in my delegate.

Editable TextView with Second NavBar - Text appears, but too late

Editable TextView with Second NavBar - Text appears, but too late.
The app has a single Navigation Controller.
I have an iPhone App that has basically three levels.
Level 1 - Table with category Names
Level 2 - Table with list of items for selected category
Level 3 - Tabbed View with several views, including UITextView for details of item
One to these Tabbed Views with a TextView is editable.
When the user taps in the editable TextView the KeyBoard
appears. User can type in the TextView. Characters appear
as they are typed.
At the top of this Level 3 TextView there is a NavBar (present for all 3 levels with
changes) with a BackButton and a "home->Level1" button on the right.
All works just fine until in the editable TextView I add a second NavigationBar
below the existing NavBar. This second NavBar has two buttons
as well. They are Save/Cancel.
When I click these Save and Cancel buttons the correct action
methods are reached. All is perfect with one exception, The text
which is typed does not appear in the TextView until either
the Save or the Cancel button is touched. The relevant Button setup and
action methods in my TabViewController.m are below. I need to persist this
data.
I thought that getting a Notification from the TextView and the action handleTextChange would do the trick, but no luck. I am stuck.
.........
- (void)loadView {
self.myTextView = [[UITextView alloc] init];
self.myTextView.delegate = self;
self.view = self.myTextView;
//UITextViewTextDidChangeNotification
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
selector:#selector(handleTextChange:)
name:UITextViewTextDidChangeNotification
object:nil];
NSLog(#"Registered DG_HandleChangeTextNotification with notification center.");
}
- (void)handleTextChange:(NSNotification * )note
{
[self.myTextView setNeedsDisplay] ;
NSLog(#"...Handled Text Change.");
}
- (void)textViewDidBeginEditing:(UITextView *)textView
{
// provide my own Done/Save button to dismiss the keyboard
saveNavigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
saveNavigationBar.barStyle = UIBarStyleBlackOpaque;
UINavigationItem *doneItem = [[UINavigationItem alloc] init];
doneItem.title = #"My Notes";
UIBarButtonItem *doneItemButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemSave
target:self action:#selector(saveAction:)];
UIBarButtonItem *cancelItemButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self
action:#selector(cancelAction:)];
[doneItem setRightBarButtonItem:doneItemButton animated:NO];
[doneItem setLeftBarButtonItem:cancelItemButton animated:NO];
[saveNavigationBar pushNavigationItem:doneItem animated:NO];
[self.view addSubview:saveNavigationBar];
[doneItem release];
[cancelItemButton release];
[doneItemButton release];
}
- (void)saveAction:(id)sender
{
// finish typing text/dismiss the keyboard by removing it as the first responder
self.text = self.myTextView.text;
[self.saveNavigationBar removeFromSuperview];
[self.myTextView resignFirstResponder];
}
- (void)cancelAction:(id)sender
{
[self.saveNavigationBar removeFromSuperview];
[self.myTextView resignFirstResponder];
}
The Second NavBar was hiding the area of the UITextEdit
such that I had to type about four lines before I saw the text. I believe
I need to lower the height of the UITextEdit by 44 pixels.