gpt4 book ai didi

iphone - UISegmentedControl 和添加目标

转载 作者:可可西里 更新时间:2023-11-01 03:38:23 28 4
gpt4 key购买 nike

我敢肯定这对外面的人来说很容易。我有一个 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 不会触发目标方法。

作为附录,有没有更简单的方法来制作漂亮的 UIButton?我在工作时无法访问 Photoshop(尽管我确实安装了 gimp),因此不涉及图像制作的方法会很好。我无法相信 Apple 没有在 UI 中提供漂亮的 UIButton,这似乎是一个非常基本的需求?

无论如何,感谢 friend 们的帮助。

感谢您的回答...我已尝试修复,但它仍然没有触发

我现在有

[read addTarget:self action:@selector(changeFilter:) forControlEvents:UIControlEventTouchUpInside];

然后

@interface
-(void)changeFilter:(id)sender;

@implementation
-(void)changeFilter:(id)sender{}

请注意,该方法与 UISegmentedControl 在同一个类中。也许我应该尝试使用建议的 Glass 按钮 API,但如果有办法避免的话,我的老板不喜欢我使用第三方库!

最佳答案

选择器错误。它应该是,action:@selector(changeFilter:),并将事件更改为 forControlEvents:UIControlEventValueChanged,因为 UISegmentedControl 不发送任何UIControlEventTouchUpInside 事件的操作。

关于iphone - UISegmentedControl 和添加目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7161475/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com