I have a view controller called searchUpdateController, it has a button to push a new view controller called editController. In the editController there is a button called Save and it contains the following code:
searchUpdateController = [[SearchUpdate alloc] init];
[self.navigationController popViewControllerAnimated:YES];
[searchUpdateController.fieldsValArray replaceObjectAtIndex:3 withObject:joinedString];
[searchUpdateController.mainTable reloadData];
[searchUpdateController release];
fieldsValArray is a NSMutableArray property in searchUpdateController and mainTable is the tableView in the searchUpdateController. I wanted to update the content of the fieldsValArray and reload the data of the tableView. Nothing happens when I click the Save button. Any ideas what I'm missing here?
Here you are creating a new objet not using the old one in the code
searchUpdateController = [[SearchUpdate alloc] init]; set them searchUpdateController from SearchUpdateController class. so that it point to that object that pushes the editController
Dont do this -> searchUpdateController = [[SearchUpdate alloc] init];
Here you are creating new object, which is not referring to your older object
Before moving back to searchUpdateController do this:
Get second last object from self.navigationController. viewControllers, which is nothing but the searchUpdateController
Now you are having the same object so update the array data whichever you want
Now there are two possibilities to reload data:
Use NSNotification and fire a notification to parent view controller where need to reload table
Call a method of parent class which will reload table
Hope this is what you want.
Related
I tried doing this in LogFrameViewController to get a hold of the table view:
FrameSettingsTableViewController *FrameSettingsTableViewController = [[FrameSettingsTableViewController alloc] initWithNibName:#"FrameSettingsTableViewController" bundle:nil];
[[FrameSettingsTableViewController frameSettingsTableView] reloadData];
I was able to set some other properties in FrameSettingsTableViewController but can't reload the data, setting a breakpoint shows the table view to be nil.
How do I go about getting a reference to that table view from within my LogFrameViewController in order to reloadData?
You'll have to rename your variable to something that is not the class name
FrameSettingsTableViewController *frameSettingsTableViewController = [[FrameSettingsTableViewController alloc] initWithNibName:#"FrameSettingsTableViewController" bundle:nil];
[[frameSettingsTableViewController frameSettingsTableView] reloadData];
Note the lower-case 'f' in frameSettingsTableViewController
I have a UIScrollView that contains a UIImageView and a UISearchDisplayController. When the user taps on the image, the search display controller appears. I’m filtering a list based on the search text and the table associated with the UISearchDisplayController is correctly updated. When the user taps on an row in the table, I am receiving the didSelectRowAtIndexPath. That’s what is working. (I used this tutorial to help me implement the UISearchDisplayController.)
However, I can’t figure out how to (a) remove the UISearchDisplayController (i.e., the search box and table) from within didSelectRowAtIndexPath and (b) how to pass information about the row that was selected to the UIScrollView.
Thanks.
A) You should be able to dismiss the UISearchDisplay Controller with something like:
[searchDisplayController setActive:NO animated:YES];
B) I am assuming you are launching a new view controller to display information about the row selected? If so, do something like this:
MyViewController *viewController = [[MyViewController alloc] initWithNibName:#"myNibName" bundle:nil];
MyObject *object = [allObjects objectAtIndex:indexPath.row];
// pass object to view controller's "object" property
viewController.object = object;
[self.navigationController pushViewController:viewController animated:YES];
Sorry if anything is out of syntax, didn't type into xcode.
- (void)addPlace {
//set up add controller
PlacesAddViewController *addController = [[PlacesAddViewController alloc] initWithStyle:UITableViewStyleGrouped];
addController.delegate = self;
// create new place and assign it to add controller
Place *newPlace = [NSEntityDescription insertNewObjectForEntityForName:#"Place" inManagedObjectContext:self.managedObjectContext];
addController.place = newPlace;
// set up navigation controller
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addController];
[self presentModalViewController:navigationController animated:YES];
// release controllers
[navigationController release];
[addController release];
}
The method insertNewObjectForEntityForName is returning a new instance of Place correctly when I try adding a place initially, but when I delete a place from the list then press "+" this method is called again and this time insertNewObjectForEntityForName returns the place that was just deleted.
Can anyone give me some ideas as to what is happening? I know this method returns an autoreleased object -- not sure if this has anything to do with it.
UPDATE: I think it's happening because right before the add view controller displays you can see the new object being inserted at the top of table view controller in the first row. When the add view controller is displayed the new object is indeed a new instance. Also, if I save this object it correctly replaces the row in the table view controller with the correct information. So maybe this has something to do with my table view below. Ahhh, I just figured it out and answered my own question. My cellForRowAtIndexPath was using a reused cell and the information was displaying the latest cell deleted. I've since fixed this. Thanks though for the reassurance it wasn't the code above.
That can't be happening given the code above. Why do you think that is what's happening? Add NSLog statements to output properties of newPlace after it has been inserted and before you present the navigationController to verify this. I would also do some logging in addController. Whatever is going on, the problem is likely there. What is the #property definition for the place property in addController? Add some more code and I'll try to help more.
Im fairly new to Objective-C. I am in the process of passing an array from an NSObject to a view controller (not my root). The NS object file, finishes with the array poolArray.
Ive also used self.poolArray = nil; in void(dealloc). When passing this to my view controller, what are the steps I have to take?
Edit: To be more specific to my cause, what if I was just to deal with two view controllers?
-(void)createData {
//poolFixtures being the text within each cell of my table view.
NSMutableArray *poolFixtures;
groupSections=[[NSMutableArray alloc] initWithObjects: #"Pool Stages", nil]
poolFixtures=[[NSMutableArray alloc] init];
[poolFixtures addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:#"This is a name",#"name",nil]];
fixtureData=[[NSMutableArray alloc] initWithObjects: poolFixtures, nil];
[poolFixtures release];
}
I have a similar set up for my second view controller. However, the titles needed for the second one require me to download data from a html file, parse them into the format i want etc. When used in the second view controller it takes a long time (I presume because of the html loading time). What I am trying to accomplish (what I thought i could do with an NSobject), is starting the data collection as soon as the user opens the app; so, by the time the user gets to the second view controller, it is loaded and ready.
Therefore I am wondering if I could do the downloading, and parsing in the root view controller, and send the array across to the second view controller for use when needed. I thought I would be able to use the createData part of my root implementation to do so.
For this, my suggestion is implement delegate methods. I guess u know about protocols in objective C. More info about delegate pattern.
Steps to do.
1. After ur app is launched, the view controller set the delegate and start downloading in background thread.
2. After the download is finished, the downloaded data will be set through the delegate methods.
Hope u will get my point. Any doubt, post it here.
I may be misunderstanding you, but this is what you typically do....
Object obj = [[Object alloc] init];
ViewController *vc = [[ViewController alloc] initWithNibName:#"NibName" bundle:nil];
// this is a public property of the viewcontroller
vc.array = [object methodThatReturnsArray];
[self.navigationController pushViewController:vc];
This is what the methodThatReturnsArray would look like
-(NSArray *)methodThatReturnsArray
{
NSArray* array = [[[NSArray alloc] init] autorelease];
// some code here that adds to the usefulness of the array
return array;
}
Hi to all,
I passed a variable from first.m to seViewController.m. I'm able to print that variable using NSLog(#variable) but I'm unable to use textField.text=variable. How to print that variable in a textbox?
First.m
-(void)buttonPressed01
{
seViewController *seView = [[seViewController alloc] init];
[seView insert:myString];
[self.navigationController popViewControllerAnimated:YES];
}
seviewcontroller.m
-(void)insert:(NSString*) myString
{
NSLog(#"%#",myString);
textField.text=[NSString stringWithFormat:#"%#",myString];
}
seViewController *seView = [[[seViewController alloc] initWithNibName:#"seViewController" bundle:nil] autorelease];
[seView insert:String];
[[self navigationController] pushViewController:seView animated:YES];
seviewcontroller.m
-(void)insert:(NSString*) myString
{
NSLog(#"%#",myString);
textField.text=myString;
}
Until your seViewController is loaded you can not use its outlets, here you are using textField. It won't set text because after seViewController *seView = [[seViewController alloc] init]; the view is initialized but still you need to load its view in memory in order to use its outlet. so if you are using its view then after addingSubview, or presenting modalView or, pushing it on navigation stack call that method.
or else you should have a string in seviewcontroller which you will set and when controller's will be loaded in memory viewDidLoad just do what you are doing right now in insert method, set TextField's text.
Also, I am not sure what you want to do with seView? why you are creating new instance and not using it ? May be you have created this controller earlier and you want to change that controller's textField text not the new one. Then in that case you should refer that controller not this one because its totally different object.
Thanks
When you pop from stack it loads the instance of the view controller you pushed in to stack. Here you created a new instance and set the text field and loads the instance in the stack. Thats why text field does not show the value to set. If you want to pass the value to the class you nee to pass the value using some singleton class or app delegate.
I think its not working because you are passing this variable to a new instance of your seViewController while you are popping it in the next line. You have to get the same instance as -
seViewController *seView = (seViewController*)[self parentViewController];
[seView insert:myString];
[self.navigationController popViewControllerAnimated:YES];
You can use this one if what I understood is correct,
you can retrieve the array of viewControllers from the navigation controller.
You dont need to initialize the view controller and this wont work as explained above.