Referencing a TableViewController property when it is buried on a NavigationController stack - uinavigationcontroller

I have a UINavigationController with two UITableViewControllers pushed onto its stack. Is there any way to reference a property on the first TableViewController that is under the second? I would like to do this in the second controller's viewWillAppear method.
Thank you for any help you can give....

I figured it out it is...
[[[[self navigationController] viewControllers] objectAtIndex:0] MyProperty];
index could be any number on the stack... Mine happens to be the first one so its index is 0...

Related

Autoscrolleable TableView

I think this is an easy one, but I can't solve it by myself.
I'm using a TableView from QML, and from Qt with a timer I'm sending info to the TableView to generate new rows.
I want the TableView autoscroll itself and always showme the last row I add
Use
ListView.positionViewAtEnd();
to scroll to the end of list or use
ListView.positionViewAtIndex(int index, PositionMode mode)
to scroll to specified index.
Pay attention, you must call this functions only after the list was loaded (generally in Component.onCompleted)
I find an answer
TableView.positionViewAtRow( TableView.rowCount -1, ListView.End)
I used folibis/Benjamin answer but I have to do it with a TableView, I found this answer to my problem, hope it helps some one else

QGraphicsScene::clear() clearing scene but not the view

I use a custom class (Configuration) derived from QGraphicsItem and I add its objects to a QGraphicsScene, which is then displayed in a QGraphicsView. Usual stuff. What Im doing exactly is drawing a tree, in multiple steps, one level a step, each node beeing my custom QGraphicsItem.
Here a screenshot. The tree happens to be sequential in the simple case.
I first draw the root node. The signal that triggers that is fired after the user entered a string.
void MainWindow::drawRootSlot(ConfigTreeBuilder & builder)//this is a slot
{
c_scene->clear(); //the clear cause headache. i'll expain
Configuration* conf = new Configuration(builder.getNodesX(), builder.getNodesY(),builder.getNodesConfig());
//code
c_scene->addItem(conf);
//code
}
Each subsequent Configuration is draw inside another slot.
void MainWindow::configTreeSlot(ConfigTreeBuilder & builder) //SLOT!!!
{
while(builder.chooseNextNode()) {
Configuration* conf = new Configuration(builder.getNodesX(), builder.getNodesY(), builder.getNodesConfig());
//code, while loop
QGraphicsLineItem *edge = c_scene->addLine(QLineF(*(parentsPoint), conf->getLeftOrigin()));
edge->setZValue(-1); //below the Configuration item
c_scene->addItem(conf);
}
}
All works fine when done for the first time. When I enter a new string, resetting the tree, dark magic happens. What I expected to it do is: call drawRootSlot(), deleting the whole tree (c_scene->clear()), draw a new root node. And, if I put a debugger breakpoint inside drawRootSlot() this is exactly what happens! But when I run it (without breakpoints), what I get is this:
The previous tree got mangled, but not deleted. The scene gets indeed cleared of its items (printed that) but the view does not reflect that. But again, when I put a breakpoint inside drawRootSlot() thhe view and the scene are in sync.
I tried to delete the scene object, and instaciate a new one instead of calling c_scene->clear(), to guarantee it empty. Then the changes are reflected on the view (the first time drawing always works).
So, I have no idea what to deduce from these symptoms. It works as expected with a breakpoint or with a freshh QGraphicsScene object. It does not when just using c_scene->clear(). One couldsay I just messed up the parent-object/child-object relation, but clear() does remove items from the view... I tried calling it right after c_scene->addItem().
What is this sorrcery? One that makes me believe I'm not actually stupid?
EDIT: Whats interesting and may be a hint to the real problem, is that when c_scene->clear() is called, the edges of the tree, which are normal QGraphicsLineItems, are indeed deleted in all cases (breakpoint or not). Something to do with them not beeing custom?
Ok, calling QGraphicsView::viewport().update() after QGraphicsScene::clear() solved my problems.
But does anyone have an explanaition to the behavior described above?
EDIT: Upon doing doing something else I stumbled upon the actual core of the problem: I messed up the boundingRect() of my GraphicItems, so it was below the visble item, touching only its lower edge (which got deleted, as seen on the screenshot). So now no calls to any update() methods are neccesary.
I think when you call this fitInView() for the graphicsview it cleans up the view from any artifacts that remain from a previous scene.
You can clear both scene and Graphics View
scene->clear();
ui->graphicsView->items().clear();
graphicsView = name of your graphics view
This code will delete both scene and graphics view

Unable to update table in superview from subview

I am using Xcode 4.3 and am somewhat of a nubbie in Xcode although I have been a programmer for many years.
I have a UIView called First that contains a UITable that gets its contents from files in memory. I then create a subview UIView called Second that makes changes in the data files that should change the contents of the table in First. When I remove Second and return to First, not surprising, the table is not updated. The next time First is loaded from the start, the table reflects the changes that were made.
First contains the method viewDidLoad which is used to load an NSArray from data in files with the data needed by the table. I am able to call viewDidLoad from Second but unless the table is updated from the newly changed NSArray the table will appear as it did before the changes were made.
So my problem is how to call a table method from Second so that the table in First is updated when I remove Second and return to First. I have tried calling the table method that loads the data into the table but have been unsuccessful since I get compile errors. I need to know how to call the table function in a way that will result in the table being updated when I return to first.
At least part of my problem is I don't know how the table update is called since it is not called from viewDidLoad as I might have expected.
Sorry, it is a long winded description of the problem. Much of the rest of the program that I am writing is working and I have been dealing with this issue for several months. I return every few weeks and take another stab at it but no luck so far. I really would appreciate any help you can give that will improve my understanding and fix the problem.
Here is the code after the fix: first (superview) pertinent code
-(void)viewDidLoad {
NSFileManager * fm = [[NSFileManager alloc] init];
NSError* err = nil;
NSPredicate *fltr = [NSPredicate predicateWithFormat:#"self ENDSWITH '.dir'"];
NSArray *array = [fm contentsOfDirectoryAtPath: userFolder error:&err];
self.listData = [array filteredArrayUsingPredicate:fltr];
[self.tableView reloadData]; //This does the updating must make table an IBOutlet as
[super viewDidLoad]; //described in one of the comments by m. Othman
}
Here is the code after the fix: second (subview) pertinent code. This code located
in the method where changes are made that should effect the table display
UIView * start = [self.view superview]; //this line and next two call viewDidLoad in first
UIResponder * nextResponder = [start nextResponder];
[nextResponder viewDidLoad];
Have you read the UIViewController API reference? There are more options beyond -viewDidLoad for dealing with the (re)appearance of a view...
well, UITableView Delegates called just on the loading of the view or when you ask it to reload ..
so in your viewDidLoad or any method that should changes the content of the tableview , you need to write this line
[tableview reloadData];
I hope I understand your question!!

Displaying TableView when MKAnnotation(Pin) in MKMapView touched/pressed/clicked

I want to display quite a bit of demographic data for a certain pin when someone touches on it, so providing a pop-up isn't going to cut it. I figured once the pin is touched I will just stick a tableviewController onto the NavigationController and the table view will have access to the object and display the single objects information, with one item per row and 1 section.
Anyway I'm having a hard time figuring out MKMapViewDelegates methods as it appears none of them do what I need and/or allow me to return a tableview or push that view onto the navigation controller.
I played around with:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation;
But that requires a MKAnnotationView be returned and I really just need this method to work by showing the user a table view of all the data. I was hoping for something simple like a userDidTouchPin method....
Anyone have any ideas how to accomplish what I am trying to do?
If you want to do something when the user selects the pin (and not a button on its callout), then implement the mapView:didSelectAnnotationView: delegate method and present or push your detail view controller there.
The selected annotation object is available as the annotation property of the view parameter:
- (void)mapView:(MKMapView *)mapView
didSelectAnnotationView:(MKAnnotationView *)view
{
YourDetailViewController *dvc = [[YourDetailViewController alloc] init...
dvc.annotation = view.annotation;
//present or push here
[dvc release];
}
You might need to check which type of annotation was selected (eg. if MKUserLocation was selected do nothing, etc) and you might need to cast the view.annotation to your own annotation class to easily access any custom properties you may have.

How can addChild choose the wrong insertion index?

So, In a Flex app I add a new GUI component by creating it and calling parent.addChild(). However in some cases, this causes an error in the bowels of Flex. Turns out, addChild actually does:
return addChildAt(child, numChildren);
In the cases where it breaks, somehow the numChildren is off by one. Leading to this error:
RangeError: Error #2006: The supplied
index is out of bounds. at
flash.display::DisplayObjectContainer/addChildAt()
at
mx.core::Container/addChildAt()
at
mx.core::Container/addChild()
. . at
flash.events::EventDispatcher/dispatchEventFunction()
at
flash.events::EventDispatcher/dispatchEvent()
at
mx.core::UIComponent/dispatchEvent()
at
mx.controls::SWFLoader::contentLoaderInfo_completeEventHandler()
Is this a bug in Flex or in how I am using it? It kind of looks like it could be a threading bug, but since Flex doesn't support threads that is a bit confusing.
I have noticed that it most often occurs when re-parenting a UIComponent that is already on the display list. Are you re-parenting in this situation?
Could it be possible that you are adding a child before the component has been full initialized? Maybe try adding a child after Event.COMPLETE has been broadcast?
It may not support threads but it's still asynchronous...
numChildren doesn't validly reference an existing index in the children array. Arrays in AS3 are indexed starting at 0. This means that the last item in your array as for index numChildren - 1, not numChildren.
try addChildAt(child, numChildren - 1);
OK, like a dope, I was trying to add a child to a container even though it was already there, hence the confusing "wrong insertion index" message.
cf. http://forums.devshed.com/flash-help-38/scroll-pane-scroll-bars-not-working-818174.html - what you need to do is add children to a display object, and then set the source of the scrollpane to the be the display object. Kinda like this...
Code:
var myDisplay : DisplayObject = new DisplayObject();
myDisplay.addChild(myChild1);
myDisplay.addChild(myChild2);
myDisplay.addChild(myChild3);
myDisplay.addChild(myChild4);
ScrollPane.source = myDisplay;
ScrollPane.update();

Resources