我想看看被點擊,所以我可以瓶坯正確的邏輯的按鈕。幫助與iPhone按鈕按下
這是按鈕的代碼:
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(270, 423, 60, 60)];
[button addTarget:self action:@selector(buttonPressedAction:)
forControlEvents:UIControlEventTouchUpInside];
[button setBackgroundImage:[[UIImage imageNamed:@"refreshicon.png"]
stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0]
forState:UIControlStateNormal];
button.tag = 1;
UIButton *button2 = [[UIButton alloc] initWithFrame:CGRectMake(0, 423, 60, 60)];
[button2 addTarget:self action:@selector(buttonPressedAction:)
forControlEvents:UIControlEventTouchUpInside];
[button2 setBackgroundImage:[[UIImage imageNamed:@"login.png"]
stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0]
forState:UIControlStateNormal];
button2.tag = 2;
[self.navigationController.view addSubview:button];
[self.navigationController.view addSubview:button2];
這是我如何調用buttonPressedAction
:
- (void)buttonPressedAction:(id)sender
{
UIButton* button = (UIButton*)sender;
if(button.tag == 1)
{
NSLog(@"1");
}else
{
NSLog(@"2");
}
}
但是當我使用NSLog
看到發件人值是什麼,它崩潰。
對正在發生的事情以及如何糾正它有什麼建議?
現在更正:O)謝謝!
什麼是崩潰?無法識別的選擇器,還是別的? – 2010-03-23 21:36:10
從什麼時候UIButton有一個'value'方法? – Chuck 2010-03-23 21:42:54
我也懷疑一個無法識別的選擇器。你期待[發送者值]返回什麼?據我所知,UIButton沒有像這樣的屬性。 – 2010-03-23 21:44:36