2012-03-27 99 views
0

我用Xcode 4.3创建了一个主 - 细节应用程序。iPhone添加(+)按钮操作?

在主视图中,我想在添加按钮(+)按下时向用户显示警报?

我应该在哪种方法中放置警报的代码?

任何帮助将被评价。

+0

你必须加写btn行动方法 – 2012-03-27 10:00:04

回答

1

已经创建和模板结合的方法,这样只是改变insertNewObject方法这样

- (void)insertNewObject:(id)sender 
{ 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"This is an alert" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
    [alert show]; 
} 
+0

可能在这里。我现在就试一试。谢谢。 – ivantxo 2012-03-27 10:02:57

+0

谢谢你!有用! – ivantxo 2012-03-27 10:08:45

0

你应该创造一个

-(IBAction)SomeAction{ //display your alert view }

不要忘记把它挂在IB

+0

但是,我怎么知道用户何时按下了添加(+)按钮? – ivantxo 2012-03-27 10:00:53

1

使用以下代码,

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addButtonActionName)]; 

它会在导航栏的右上角显示+按钮。

-(void) addButtonActionName { 
     // Your code for the Alert view 
} 
+0

谢谢。捕捉者的答案为我工作。我不知道你为什么不告诉我警报? – ivantxo 2012-03-27 10:15:15

+0

@ ivan.freire:我没有给你提供警报的代码,但我告诉你在哪里写警报的代码。 – Devang 2012-03-27 10:19:28

+0

谢谢。我确保我为警报设置了正确的代码,但按下+时没有任何反应。 – ivantxo 2012-03-27 10:23:04

0

下面是在导航添加BarButton酒吧

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(ShowMyAlert:)]; 

&这是为事件处理代码...

- (void)ShowMyAlert:(id)sender 
{ 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Test Alert Message" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    [alert show]; 
    [alert release]; 

}