UIButton视图无法识别的选择器发送到实例

时间:2012-01-10 15:55:38

标签: iphone

基本上我在主窗口上有一个UIToolbar,当我点击infobutton打开一个模态视图时,应用程序崩溃输出消息UIButton查看无法识别的选择器发送到实例。有人可以帮我解决这个输出消息。

 UIButton *infoItem =  [[UIButton buttonWithType:UIButtonTypeInfoLight] retain];
                      infoItem.frame = CGRectMake(250.0, 8.0, 25.0, 25.0);
                      infoItem.backgroundColor = [UIColor clearColor];
  [infoItem addTarget:self action:@selector(displayModalViewaction:) forControlEvents:UIControlEventTouchUpInside];
                       infoItem.backgroundColor = [UIColor grayColor];


 UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] 
                             initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                             target:nil
                             action:nil];


 NSArray *toolbarItems = [NSArray arrayWithObjects: settingsButton, flexItem, systemItem, flexItem, systemItem1,flexItem, systemItem2, flexItem, systemItem3, flexItem, infoItem, nil];

    [toolbar setItems:toolbarItems];



[settingsButton release];
[systemItem  release];
[systemItem1 release];
[systemItem2 release];
[systemItem3 release];
[infoItem release];
[flexItem release];

[super viewDidLoad];


- (void) playaudio: (id) sender {

// Get the file path to the song to play.

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"theme" 
                                                     ofType:@"mp3"];

// Convert the file path to a URL.

NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];

//Initialize the AVAudioPlayer.

self.audioPlayer = [[AVAudioPlayer alloc] 
                    initWithContentsOfURL:fileURL error:nil];

// Making sure the audio is at the start of the stream.

self.audioPlayer.currentTime = 0;

[self.audioPlayer play];
}

- (void)pause: (id)sender {

    if

([audioPlayer isPlaying])

{[audioPlayer pause];} 

else 

{[audioPlayer play];}

}

- (void)stop: (id) sender

 {
     [audioPlayer stop];

  }

  - (void)displayModalViewaction 
  {

self.viewController = [[Infoviewcontroller alloc] init];

UINavigationController *navigationController=[[UINavigationController alloc] init];

navigationController.navigationBar.tintColor = [UIColor brownColor];  

[navigationController pushViewController:_viewController animated:YES];

[self.view addSubview:navigationController.view];

}

感谢帮助解决这个问题。

提前致谢。

2 个答案:

答案 0 :(得分:4)

[infoItem addTarget:self action:@selector(displayModalViewaction:) forControlEvents:UIControlEventTouchUpInside];
                   infoItem.backgroundColor = [UIColor grayColor];

应该是

[infoItem addTarget:self action:@selector(displayModalViewaction) forControlEvents:UIControlEventTouchUpInside];
                   infoItem.backgroundColor = [UIColor grayColor];

因为displayModalViewaction没有收到任何参数。

答案 1 :(得分:1)

使用@selector(displayModalViewaction)添加事件;

或更改方法定义为: - (void)displayModalViewaction:(id)sender;