开发者

Need Help Using Delegate To Change UITableView

I have setup a delegate method, so that when user selects cell from VC2, it updates the header text of VC1 then pops back to it.

Now I need to add some code that will let me change the array that loads the UITableView in VC1, what is the easiest way to do this?

In VC 1

- (void)didChooseValue:(NSString *)string 
{
    self.databaseName = string;
    NSLog(@"Database Nam开发者_如何学Pythone: %@", self.databaseName);
    [self.myTableView reloadData];
}

In VC 2 - didSelectRowAtIndex

if([delegate respondsToSelector:@selector(didChooseValue:)])
    {
        [delegate performSelector:@selector(didChooseValue:) withObject:myString];
    }


You can add the code in this delegate method itself. Try something like:

- (void)didChooseValue:(NSString *)string 
{
    self.databaseName = string;
    NSLog(@"Database Name: %@", self.databaseName);
    NSMutableArray *carModels = nil;

    if([string isEqualToString:@"Mazda"])
        carModels = [[Database sharedDatabase] getMazdaModels]; 
    else if([string isEqualToString:@"Nissan"])
        carModels = [[Database sharedDatabase] getNissanModels]; //And so on depending on the number of models
    else
        carModels = [[Database sharedDatabase] getDefaultModels];

    self.carAray = carModels;
    [self.myTableView reloadData];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜