【发布时间】:2011-11-01 22:52:10
【问题描述】:
我相信这对外面的人来说是一件容易的事。我有一个 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];
}
然后
-(void)changeFilter:(id)sender{
}
由于某种原因,单击 UISegmentedControl 不会触发目标方法。
作为附录,有没有更简单的方法来制作漂亮的 UIButtons?我在工作中无法访问 Photoshop(尽管我确实安装了 gimp),所以不涉及图像制作的方法会很好。我不敢相信苹果没有在 UI 中提供漂亮的 UIButtons,这似乎是一个需要的基本东西?
无论如何,感谢朋友们的帮助。
感谢您的回答...我已尝试修复,但仍然无法触发
我现在有
[read addTarget:self action:@selector(changeFilter:) forControlEvents:UIControlEventTouchUpInside];
然后
@interface
-(void)changeFilter:(id)sender;
和
@implementation
-(void)changeFilter:(id)sender{}
请注意,该方法与 UISegmentedControl 属于同一类。也许我应该尝试使用建议的 Glass 按钮 API,但是如果有办法避免的话,我的老板讨厌我使用第三方库!
【问题讨论】:
标签: iphone objective-c ios ipad uibutton