0

我创建了一个按钮

uploadBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    uploadBtn.frame = CGRectMake(35, 340, 250, 40);
    [uploadBtn setTitle:@"Upload" forState:UIControlStateNormal];
    [uploadBtn addTarget:self action:@selector(callUpload) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:uploadBtn];

行动

-(void)callUpload
{
    UploadViewController *uploadObj = [[UploadViewController alloc]init];
    [self.navigationController pushViewController:uploadObj animated:YES];


}

但是当我点击按钮时,没有触发任何事件。请帮忙

4

1 回答 1

0

Btn 的方法应该包含它的发送者。

更新这一行。

[uploadBtn addTarget:self action:@selector(callUpload:) forControlEvents:UIControlEventTouchUpInside];

并调用方法,

-(void)callUpload : (id) sender
{
    UploadViewController *uploadObj = [[UploadViewController alloc]init];
    [self.navigationController pushViewController:uploadObj animated:YES];
}
于 2012-10-25T08:50:23.270 回答