iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iphone – UISegmentedControl和添加目标大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我相信这对那里的某个人来说很容易.我有一个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),因此一种不涉及图像制作的方法会很好.我无法相信苹果在UI中没有提供漂亮的UIButton,这似乎是一个需要的基本要素?

无论如何,感谢帮助误区友.

谢谢你的答案…我已经尝试了修复,但它仍然没有解决

我现在有

[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和添加目标全部内容,希望文章能够帮你解决iphone – UISegmentedControl和添加目标所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: