在按钮上调用方法

时间:2010-12-24 09:05:55

标签: cocoa

它是在按钮“gobtn”上调用名为“inserttable”的方法的正确方法,在appdelegate中声明了whitch方法吗?

gobtn= [[UIButton alloc] initWithTitle:nil style:UIBarButtonItemStyleBordered target:self  action:@selector(inserttable:)];

1 个答案:

答案 0 :(得分:0)

所以我想你想让这个按钮调用-(void)inserttable{}这是一个委托方法吗?

一种方式是

gobtn= [[UIButton alloc] initWithTitle:nil style:UIBarButtonItemStyleBordered target:self  action:@selector(inserttable)]; // without the colon if the method takes no parameters..

-(void)inserttable
{
//Do what stuff you want
.
.
[appdelegate inserttable];// or this if you intend on passing the buttons action to call
                         //inserttable of the appdelegate. 
}

gobtn= [[UIButton alloc] initWithTitle:nil style:UIBarButtonItemStyleBordered target:adddelegate  action:@selector(inserttable)]; // without the colon if the method takes no parameters..