IBaction的目标C问题

时间:2015-09-29 01:41:16

标签: ios objective-c uitableview ibaction

我是Objective C的新手。在UITableViewController我添加+Edit按钮连接到我的IBaction

- (IBAction)add:(id)sender {
    UIBarButtonItem *addButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 
target:self action:@selector(addButtonPressed:)];
    self.navigationItem.rightBarButtonItem = addButton;
    UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];
    [button setUserInteractionEnabled:NO];
    cell.accessoryView = button;
}

它给了我两个问题undeclared addButtonundeclared cell identifier。但是,我在故事板原型单元格中声明了cell

2 个答案:

答案 0 :(得分:0)

您必须在ViewDidLoad中添加以下代码。

string result = String.Format("{0:0.00}",  this.Hours).PadLeft(8, '0');

并为“addButtonPressed”制作一个IBAction

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

并且您使用tableview自定义单元格,然后您必须声明和注册单元格标识符。

e.g

-(IBAction)addButtonPressed:(id)sender
{
// your code
}

这对你有帮助..

答案 1 :(得分:0)

您的UIButton可能已在故事板中创建。

如果是这种情况,意味着您已将UIViewController添加到 InterfaceBuilder 中的addButtonPressed:,则您不应该添加UIButton。

您也不必使用@selector来调用方法:addButtonPressed:。相反,删除正在IBAction方法中执行的代码,并添加,将其添加到您的- (IBAction)add:(id)sender { // Code from // AddButtonPressed: // Goes here } 方法中,如下所示:

f