2009-08-24 4 views
0

Ich habe eine Frage zu UITableviews, dem Stack und dem Entfernen von Komponenten oder dem Verstecken von Komponenten auf dem Stack. zuerst Ich habe eine Funktion, die eine Komponente (eine Schaltfläche) hinzufügt;removeFromSuperView ... Wie kann ich alle meine Komponenten aus jeder Controlleransicht entfernen?

-(void)addComponent 
{ 
[self.navigationController.view addSubview:playButton]; 
} 

Ich nenne diese Funktion in meinem

DidSelectRowAtIndexPath

So weit, so gut.

Jetzt kommt der "Spaß" Teil.
Ich habe eine andere Funktion, die mit einem barbuttonitem angebracht ist

, die auf dem Stapel einen nächsten Controller schiebt

-(void)lastView:(id)sender 
{ 
selectedRow = [self.tableView indexPathForSelectedRow]; 

NSUInteger row = selectedRow.row; 

NSUInteger section = selectedRow.section; 

[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:section] animated:YES scrollPosition:UITableViewScrollPositionBottom]; 

[self tableView:[self tableView] didSelectRowAtIndexPath:selectedRow]; 

NSDictionary *dictionary = [self.tableDataSource objectAtIndex:selectedRow.row]; 

//Get the children of the present item. 

NSArray *Children = [dictionary objectForKey:@"Children"]; 

rvController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:[NSBundle mainBundle]]; 

//Increment the Current View 

rvController.CurrentLevel += 1; 

//Push the new table view on the stack 

[self.navigationController pushViewController:rvController animated:NO]; 

rvController.tableDataSource = Children; 

[rvController release]; 

} 

} 

Ich wünsche den playbutton vom Bildschirm zu entfernen, aber leider removeFromSuperView funktioniert nicht. Ich vermute, es hat etwas damit zu tun, einen neuen rvController auf den Stapel zu schieben, denn wenn ich das tue, wird mein Button perfekt entfernt.

Hat jemand eine Ahnung, wie ich sicherstellen kann, dass die Schaltfläche aus ALLEN Ansichten auf dem Stapel entfernt wird und nicht nur die "aktuelle", wie es scheint.

edit:

Hier ist ein weiterer "funny" Teil wenn ich hier einigen falschen Code setzen (aber es wird einen anderen Viewcontroller drücken) wie folgen aus:

-(void)lastView:(UITableview *)tableView selectingRow:(NSIndexPath *)indexPath 
    { 

    NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row]; 

    //Get the children of the present item. 

    NSArray *Children = [dictionary objectForKey:@"Children"]; 

    rvController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:[NSBundle mainBundle]]; 

    //Increment the Current View 

    rvController.CurrentLevel += 1; 

    //Push the new table view on the stack 

    [self.navigationController pushViewController:rvController animated:NO]; 

    rvController.tableDataSource = Children; 

    [rvController release]; 

    } 

    } 

Dann scheint es zu funktionieren. Obwohl ich nicht wirklich sicher bin, aber es sieht so aus, als würde es funktionieren.

+0

Wie viele Instanzen der Schaltfläche haben Sie? – Daniel

+0

Ich habe eine Instanz erstellt –

Antwort

0

Ok interessant .. es scheint, wenn ich meine Funktion so schreibe .. alles ist gut und gut.

selectedRow = [self.tableView indexPathForSelectedRow]; 

NSDictionary *dictionary = [self.tableDataSource objectAtIndex:selectedRow.row]; 

//Get the children of the present item. 

NSArray *Children = [dictionary objectForKey:@"Children"]; 

rvController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:[NSBundle mainBundle]]; 

//Increment the Current View 

rvController.CurrentLevel += 1; 

//Set the title; 

rvController.CurrentTitle = [dictionary objectForKey:@"Title"]; 

//Push the new table view on the stack 

[self.navigationController pushViewController:rvController animated:YES]; 

rvController.tableDataSource = Children; 

[rvController release]; 

mmm aber ich bin immer noch nicht vollständig zufrieden, aber das wird für jetzt tun müssen.

Verwandte Themen