我确信这对于那里的人来说很容易。我有我使用一个按钮(以免必须使用讨厌的默认按钮),我遇到麻烦目标工作....代码如下UISegmentedControl和添加目标
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
//read.buttonType = UIBarStyleBlackOpaque;
UISegmentedControl* read = [[[UISegmentedControl alloc] initWithFrame:CGRectMake(5, 50, 310, 54)] autorelease];
[read insertSegmentWithTitle:@"Read" atIndex:0 animated:NO];
read.tintColor = [UIColor colorWithRed:0.3 green:0.3 blue:0.9 alpha:1];
read.segmentedControlStyle = UISegmentedControlStyleBar;
[read addTarget:self action:@selector(changeFilter:sender:) forControlEvents:UIControlEventTouchUpInside];
[read setTag:1];
[self.view addSubview:read];
}
,然后一个UISegmentedControl
-(void)changeFilter:(id)sender{
}
由于某些原因,单击UISegmentedControl不会触发目标方法。
作为一个附录,有没有一种更简单的方法来使漂亮的UIButtons?我在工作中无法使用Photoshop(尽管我已经安装了gimp),所以一种不涉及图像制作的方式会很好。我无法相信苹果在用户界面中不提供漂亮的UIButtons,似乎需要这样一个基本的东西?
无论如何,感谢您的帮忙mis amigos。
感谢您的答案......我已经试过了修复,但它仍然不火
我现在有
[read addTarget:self action:@selector(changeFilter:) forControlEvents:UIControlEventTouchUpInside];
然后
@interface
-(void)changeFilter:(id)sender;
和
@implementation
-(void)changeFilter:(id)sender{}
请注意,方法与UISegmentedControl在同一个类中。也许我应该尝试使用建议的Glass按钮API,但如果有办法避免它,我的老板会讨厌使用第三方库!
我已经做了这一点,它仍然没有发射 – shaw2thefloor
更改的事件了。检查我编辑的答案。 – EmptyStack
啊,那张票...要求所有的答案。 – shaw2thefloor