自定义分段按钮后,操作不会发生

时间:2012-08-03 06:24:03

标签: iphone objective-c ios5 uisegmentedcontrol

我正在使用MCSegementcontrol类来自定义这样的分段控件

NSArray *items = [NSArray arrayWithObjects:@"Supplier", 
                                           @"Status",
                                           @"Lead Date", 
                                           @"A-Z" ,nil];

segmentedControl = [[MCSegmentedControl alloc] initWithItems:items];

[segmentedControl addTarget:self 
                     action:@selector(totalAction:)
           forControlEvents:UIControlEventValueChanged];

[segmentedControl setFrame:CGRectMake(20, 30, 728 , 70)];
segmentedControl.layer.cornerRadius = 15.0;
segmentedControl.layer.masksToBounds = YES;
segmentedControl.selectedSegmentIndex = 0;

segmentedControl.tintColor = [UIColor colorWithRed:0.0/255.0 green:77.0/255. blue:146.0/255.0 alpha:1.0];


segmentedControl.selectedItemColor = [UIColor whiteColor];
segmentedControl.unselectedItemColor = [UIColor whiteColor];

UIFont *font = [UIFont boldSystemFontOfSize:25.0f];
NSDictionary *attributes = [NSDictionary dictionaryWithObject:font
                                                       forKey:UITextAttributeFont];
[segmentedControl setTitleTextAttributes:attributes 
                         forState:UIControlStateNormal];

[self.view addSubview:segmentedControl];
[segmentedControl release]; 

但它没有对此执行操作[segmentedControl addTarget:self action:@selector(totalAction :) forControlEvents:UIControlEventValueChanged];

关于我已完成的totalAction的动作

-(IBAction)totalAction:(id)sender
{

segmentedControl =  sender;
 NSLog(@"total action %d", [sender tag]);
 if([segmentedControl selectedSegmentIndex] == 0){
    [self getReportDetailtableData:userNameStr1 password:passwordStr1 total:total startDate:startDate enddate:endDate mgrId:MgrID shortBy:@"supplier"];

 //   [self supplier:self];

 }
 else if([segmentedControl selectedSegmentIndex] == 1){

    [self status:self];

 }

 else if([segmentedControl selectedSegmentIndex] == 2){

    [self dateBy:self];

 }
 else if([segmentedControl selectedSegmentIndex] == 3){

    [self alphabetically:self];

 }
}

但是这个IBAction没有调用UIControlEventValueChanged。

请给我一些建议。我已经坚持了一整天,但没有找到解决方案。

0 个答案:

没有答案