在一个视图中创建两个操作表
我在一个视图中创建了两个操作表。有两个按钮,每个按钮都会启动一个操作表。
问题:当我按下两个操作表中的第一个选择时,会触发相同的操作。
这是我的代码:
-(IBAction) ChangeArrow:(id)sender{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Change Arrow"
delegate:self
cancelButtonTitle:@"cancel"
destructiveButtonTitle:@"Red"
otherButtonTitles:@"Blue",@"Black",nil];
[actionSheet showInView:self.view];
[actionSheet release];}
- (void) actionSheet: (UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{
if (buttonIndex ==[actionSheet destructiveButtonIndex]) {
self.bar.image=[UIImage imageNamed:@"red"];
}
else if(buttonIndex == 1){
self.bar.image=[UIImage imageNamed:@"blue"];
}
else if(buttonIndex == 2){
self.bar.image=[UIImage imageNamed:@"dark"];}
}
//第二个操作表:
-(IBAction) Background:(id)sender{
UIActionSheet *actionSheet2 = [[UIActionSheet alloc] initWithTitle:@"Change Background"
delegate:self
cancelButtonTitle:@"cancel"
destructiveButtonTitle:@"Sky"
otherButtonTitles:@"Thumbs",@"Smiley",nil];
[actionSheet2 showInView:self.view];
[actionSheet2 release];
}
- (void) actionSheet2: (UIActionSheet *)actionSheet2 didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex ==[actionSheet2 destructiveButtonIndex]) {
self.background.image=[UIImage imageNamed:@"sky"];
}
else if(buttonIndex == 1){
self.background.image=[UIImage imageNamed:@"thumbs"];
}
else if(buttonIndex == 2){
self.background.image=[UIImage imageNamed:@"smiley"];}
}
I created two action sheets in one view. There are two buttons, each will initiate one action sheet.
The problem: when i press on first choice in both action sheets the same action is triggered.
Here's my code:
-(IBAction) ChangeArrow:(id)sender{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Change Arrow"
delegate:self
cancelButtonTitle:@"cancel"
destructiveButtonTitle:@"Red"
otherButtonTitles:@"Blue",@"Black",nil];
[actionSheet showInView:self.view];
[actionSheet release];}
- (void) actionSheet: (UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{
if (buttonIndex ==[actionSheet destructiveButtonIndex]) {
self.bar.image=[UIImage imageNamed:@"red"];
}
else if(buttonIndex == 1){
self.bar.image=[UIImage imageNamed:@"blue"];
}
else if(buttonIndex == 2){
self.bar.image=[UIImage imageNamed:@"dark"];}
}
//Second Action sheet:
-(IBAction) Background:(id)sender{
UIActionSheet *actionSheet2 = [[UIActionSheet alloc] initWithTitle:@"Change Background"
delegate:self
cancelButtonTitle:@"cancel"
destructiveButtonTitle:@"Sky"
otherButtonTitles:@"Thumbs",@"Smiley",nil];
[actionSheet2 showInView:self.view];
[actionSheet2 release];
}
- (void) actionSheet2: (UIActionSheet *)actionSheet2 didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex ==[actionSheet2 destructiveButtonIndex]) {
self.background.image=[UIImage imageNamed:@"sky"];
}
else if(buttonIndex == 1){
self.background.image=[UIImage imageNamed:@"thumbs"];
}
else if(buttonIndex == 2){
self.background.image=[UIImage imageNamed:@"smiley"];}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将每个操作表上的标记属性设置为不同的值。然后您可以检查 sender.tag 以查看哪个操作表调用了您的方法。
前任。
然后
Set the tag property on each actionsheet to a different value. Then you can check sender.tag to see which action sheet called your method.
Ex.
Then