2010-12-01 22 views
0

閱讀下面的代碼:選擇UIToolbar的一個項目不起作用

// Creiamo la toolbar sotto 
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 372, 320, 44)]; 
toolbar.tintColor = [UIColor blackColor]; 
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"imgImpostazioniToolbar.png"]]; 
UIBarButtonItem *pulsanteImpostazioni = [[UIBarButtonItem alloc] initWithCustomView:imageView]; 
[pulsanteImpostazioni setTarget:self]; 
[pulsanteImpostazioni setAction:@selector(prova)]; 
[imageView release]; 
UIBarButtonItem *spaziatore = [[UIBarButtonItem alloc]       initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; 
NSArray *buttons = [[NSArray alloc] initWithObjects:spaziatore, pulsanteImpostazioni, spaziatore, nil]; 
[toolbar setItems:buttons animated:NO]; 
[self.view addSubview:toolbar]; 
[buttons release]; 

我可以正確地看到我的形象,但是當我嘗試觸摸它沒有發生。 我沒有正確設置「pulsanteImpostazioni」的選擇器? 謝謝

P. 「prova」只包含一個NSLog。

回答

0

我覺得在這種模式下的解決方案:

UIButton *pulsanteImpostazioni = [UIButton buttonWithType:UIButtonTypeCustom]; 
[pulsanteImpostazioni setFrame:CGRectMake(0, 0, 200, 50)]; 
[pulsanteImpostazioni setImage:[UIImage imageNamed:@"imgImpostazioniToolbar.png"] forState:UIControlStateNormal]; 
[pulsanteImpostazioni addTarget:self action:@selector(prova) forControlEvents:UIControlEventTouchUpInside]; 
UIBarButtonItem *pulsanteImpostazioni = [[UIBarButtonItem alloc] initWithCustomView:pulsanteImpostazioni]; 

不管怎樣,謝謝您的回答=)

0

嘗試 [pulsanteImpostazioni setAction:@selector(prova:)];

冒號在選擇名稱事項的末尾。