在按钮上单击如何调用类并同时在数据库中插入值

时间:2011-04-29 08:01:02

标签: iphone objective-c

我有一个应用程序,其中有一个部分,在按钮单击上我将值插入数据库,并在相同的按钮操作上调用视图控制器。这是我的按钮操作代码;

//this is my button action 
-(IBAction)Start:(id)sender{

    Gjourney = mTextJourney.text;
    Glocation = mTextLocation.text;
    Gmessage =mDescription.text;
    // Insert into the database function
    [self saveInDatabase];

    app=(JourneyAppDelegate *)[[UIApplication sharedApplication]delegate];
    //this is the class which i want to get called when i click on the button
    BreadcrumbViewController *st = [[BreadcrumbViewController alloc]initWithNibName:@"BreadcrumbViewController" bundle:nil];

    [app.navController pushViewController:st animated:YES]; 
}

我的问题是,当单击开始按钮时,我的数据保存在数据库中,但未调用BreadcrumViewController类。可能是什么问题?

3 个答案:

答案 0 :(得分:1)

[self.navController pushViewController:st animated:YES];

答案 1 :(得分:0)

标准视图传递是这样的,我导入标题,然后

BreadcrumbViewController *detailViewController = [[BreadcrumbViewController alloc] initWithNibName:@"BreadcrumbViewController" bundle:nil];
        // ...
        // Pass the selected object to the new view controller.
        [self.navigationController pushViewController:detailViewController animated:YES];
        [detailViewController release]; 

如果不起作用,请检查导航控制器是否正常 ,你可能没有在你的代表中设置

答案 2 :(得分:0)

-(IBAction)Start:(id)sender{
Gjourney = mTextJourney.text;
Glocation = mTextLocation.text;
Gmessage =mDescription.text;
// Insert into the database function
[self saveInDatabase];

viewcontroller=[ViewController alloc ] initWithNibName:@"ViewController"];
[self.navigationController pushViewController:viewController];
[viewController release];
}

此代码应该可以正常工作。