XCode重命名插座标签方向

XCode重命名插座标签方向,xcode,xcode4,xcode4.5,Xcode,Xcode4,Xcode4.5,来自我创建的字符串(使用xcode 4.5.2) 当然还有: @property (strong, nonatomic) IBOutlet UILabel *labelField_x; @property (strong, nonatomic) IBOutlet UILabel *labelField_y; @property (strong, nonatomic) IBOutlet UILabel *labelField_z; 我希望能够在iAction中,通过从数组中选择正确的键,从字符串

来自我创建的字符串(使用xcode 4.5.2)

当然还有:

@property (strong, nonatomic) IBOutlet UILabel *labelField_x;
@property (strong, nonatomic) IBOutlet UILabel *labelField_y;
@property (strong, nonatomic) IBOutlet UILabel *labelField_z;
我希望能够在iAction中,通过从数组中选择正确的键,从字符串中选择要使用的标签。而不是做if或BOOL语句,重复我自己。例如,我有:

- (IBAction)buttonPressed:(UIButton *)sender;
{
    if (is_x){

        NSString *digit = sender.currentTitle;
            if (!pressedDecimal){
                labelField_x.text = [labelField_x.text stringByAppendingString:digit];
            }else if (count <= 1){
                labelField_x.text = [labelField_x.text stringByAppendingString:digit];
            }
                                      .
                                      .
                                      .
    }
    else if (is_y){

        NSString *digit = sender.currentTitle;     
            if (!pressedDecimal){
                labelField_y.text = [labelField_y.text stringByAppendingString:digit];
            }else if (count <= 1){
                labelField_y.text = [labelField_y.text stringByAppendingString:digit];
            }
                                      .
                                      .
                                      .

    }
    else if (is_z){

        NSString *digit = sender.currentTitle;
            if (!pressedDecimal){
                labelField_z.text = [labelField_z.text stringByAppendingString:digit];
            }else if (count <= 1){
                labelField_z.text = [labelField_z.text stringByAppendingString:digit];
            }
                                      .
                                      .
                                      .
    }
}

谢谢。

我不完全确定你在干什么,但如果你想省去一些打字的时间,为什么不这样做:

// assign the label you want to use to a local variable

UILabel *selectedLabel;
selectedLabel = nil;
if (is_x) {
    selectedLabel = labelField_x;
} else if (is_y) {
    selectedLabel = labelField_y;
} else if (is_z) {
    selectedLabel = labelField_z;
}

// now work with selectedLabel so you don't have to repeat yourself

if (!pressedDecimal){
    selectedLabel.text = ...
或者,您甚至可以将IBOutlet属性中的标签直接粘贴到字典中,以便快速获得任何给定字符(字符串)的正确标签:


谢谢你,我很抱歉没有告诉你我到底在做什么,我只是想让我的代码的某些部分不那么重复。
labelField_@"%@".text,[myList 0]  = [labelField_@"%@".text,[myList 0] stringByAppendingString:digit];
// assign the label you want to use to a local variable

UILabel *selectedLabel;
selectedLabel = nil;
if (is_x) {
    selectedLabel = labelField_x;
} else if (is_y) {
    selectedLabel = labelField_y;
} else if (is_z) {
    selectedLabel = labelField_z;
}

// now work with selectedLabel so you don't have to repeat yourself

if (!pressedDecimal){
    selectedLabel.text = ...
// create a lookup dictionary (once, e.g. in awakeFromNib)

NSDictionary *labelForCharacter;
labelForCharacter = @{
    @"x" : labelField_x,
    @"y" : labelField_y,
    @"z" : labelField_z
};

 // get the label for "z"

UILabel *selectedLabel;
selectedLabel = labelForCharacter[@"z"];