UISegmentedControl and adding targets

I am sure it is just for someone. I have a UISegmentedControl that I use as a button (so as not to use the unpleasant default button), and I am having problems getting the target to work ... the code is as follows

- (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];



}

and then

-(void)changeFilter:(id)sender{

}

for any reason, clicking on the UISegmentedControl does not start the target method.

As an add-on, is there an easier way to make pretty UIButtons? I do not have access to Photoshop at work (although I have gimp installed), so a method that does not include creating images will be good. I can’t believe that the apple did not provide attractive UIButtons in the user interface, it seems that this is very important?

Anyway, thanks for the help of mis amigos.

... ,

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

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

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

, , UISegmentedControl. , API Glass, , , , !

+5
3

. , action:@selector(changeFilter:), forControlEvents:UIControlEventValueChanged, UISegmentedControl UIControlEventTouchUpInside.

+8

.h u

     -(void)changeFilter:(id)sender;

change this 

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

To

 [read addTarget:self action:@selector(changeFilter:) forControlEvents:UIControlEventValueChanged];
+5

, @selector (changeFilter:).

As for your second question, ios5 will help you there ... but I still can not say much about it. At the moment, you can use some uibutton classes that people have made to easily make some nice buttons. Here is one:

http://hboon.com/glass-buttons-in-iphone-apps-without-using-image-files/

+1
source

All Articles