为什么我的分段控件没有反应?

时间:2013-08-23 12:48:05

标签: ios uisegmentedcontrol

我正在使用Xcode中的iPhone应用程序,我想使用具有4种不同选择的分段控件。

我想知道我做错了什么以及当我点击它时NSLog消息为什么不显示?

这是我的代码:

.h文件:

#import <Foundation/Foundation.h>

@interface Format : UIViewController{

    IBOutlet UISegmentedControl *papper;
}

@property (nonatomic, retain) IBOutlet UISegmentedControl *papper;

-(IBAction)papperskontrollSwitched:(id)sender;

.m文件:

#import "Format.h"

@implementation Format

@synthesize papper;

-(IBAction)papperskontrollSwitched:(id)sender{
    if(papper.selectedSegmentIndex==0){

        NSLog(@"A5 valdes");
    } 

    else if(papper.selectedSegmentIndex==1){

        NSLog(@"A4 valdes");
    }

    else if(papper.selectedSegmentIndex==2){

        NSLog(@"A3 valdes");
    }

    else if(papper.selectedSegmentIndex==3){

        NSLog(@"Visitkort valdes");
    }
}

@end

2 个答案:

答案 0 :(得分:1)

尝试删除括号中的内容:

{
    IBOutlet UISegmentedControl *papper;
}

当你拥有它时,没有必要:

@property (nonatomic, retain) IBOutlet UISegmentedControl *papper;

答案 1 :(得分:0)

拥有一个ivar和一个@property在这里并不重要,事实上,当我在测试项目中使用这个确切的代码时,它的工作正常。

确保您的UISegmentedControl已连接到Interface Builder中的papper商店,并且您已将UISegmentedControl的'值已更改'操作与-(IBAction)papperskontrollSwitched:

enter image description here

相关问题