2010-07-30 3 views
1

Я делаю клавиатуру из UIButtons. На этой клавиатуре есть 49 UIButtons, создающие следующее:различают кнопки пользовательского интерфейса на iphone


- (void)viewDidLoad { 

    [self emoticonButtonOnTheKeyBoard_xCoordinate:0 yCoordinate:0 Emoticone_name:@"emoticon_angel.gif"  backString:@"O:-)"  keyboardView:self.view]; 
    [self emoticonButtonOnTheKeyBoard_xCoordinate:40 yCoordinate:0 Emoticone_name:@"emoticon_angry.gif"  backString:@":[email protected]"  keyboardView:self.view]; 
    [self emoticonButtonOnTheKeyBoard_xCoordinate:80 yCoordinate:0 Emoticone_name:@"emoticon_big_smile.gif" backString:@":-D"  keyboardView:self.view]; 
    [self emoticonButtonOnTheKeyBoard_xCoordinate:120 yCoordinate:0 Emoticone_name:@"emoticon_confused.gif"  backString:@":-s"  keyboardView:self.view]; 
    [self emoticonButtonOnTheKeyBoard_xCoordinate:160 yCoordinate:0 Emoticone_name:@"emoticon_cool.gif"   backString:@"B)"  keyboardView:self.view]; 
    [self emoticonButtonOnTheKeyBoard_xCoordinate:200 yCoordinate:0 Emoticone_name:@"emoticon_cry.gif"   backString:@":,-("  keyboardView:self.view]; 
    [self emoticonButtonOnTheKeyBoard_xCoordinate:240 yCoordinate:0 Emoticone_name:@"emoticon_disappoint.gif" backString:@":-|"  keyboardView:self.view]; 
    [self emoticonButtonOnTheKeyBoard_xCoordinate:280 yCoordinate:0 Emoticone_name:@"emoticon_emo.gif"   backString:@"(Emo)"  keyboardView:self.view]; 

} 
 

и методы создания:

 

- (IBAction) updatingTheTextFiledWithEmoticon 
{ 
    iPhoneClientDevAppDelegate *appDelegate = (iPhoneClientDevAppDelegate *)[[UIApplication sharedApplication] delegate]; 
    [[appDelegate.personalchatviewcontrollerReference message_textfield] setText:[[[appDelegate.personalchatviewcontrollerReference message_textfield] text] stringByAppendingString:appDelegate.EmoticonCurrentButtonValue]]; 
} 

- (void) emoticonButtonOnTheKeyBoard_xCoordinate:(int)x_coordinate yCoordinate:(int)y_coordinate Emoticone_name:(NSString *)emoticon_name 
             backString:(NSString *)stringback keyboardView:(UIView *)keyboard 
{ 
    iPhoneClientDevAppDelegate *appDelegate = (iPhoneClientDevAppDelegate *)[[UIApplication sharedApplication] delegate]; 
    appDelegate.EmoticonCurrentButtonValue = stringback; 
    UIButton* emticon_button = [UIButton buttonWithType:UIButtonTypeCustom]; 
    emticon_button.frame = CGRectMake(x_coordinate, y_coordinate, 40, 43); 
    [emticon_button setImage:[UIImage imageNamed:emoticon_name] forState:UIControlStateNormal]; 
    [emticon_button setImage:[UIImage imageNamed:emoticon_name] forState:UIControlStateHighlighted]; 
    [emticon_button setBackgroundImage:[UIImage imageNamed:@"background.png"] forState:UIControlStateNormal]; 
    [emticon_button ] 
    [keyboard addSubview:emticon_button]; 


    [emticon_button addTarget:nil action:@selector(updatingTheTextFiledWithEmoticon) forControlEvents:UIControlEventTouchUpInside]; 
} 
 

Итак, я успешно охватываемые клавиатуру, но у меня есть большая проблема. Когда я нажимаю кнопку на клавиатуре, приложение всегда возвращает последнее созданное значение кнопки. Как я могу отличить UIButtons?

Спасибо!

ответ

1

Дайте им уникальный .tag свойства (тип INT), и убедитесь, что селектор принимает отправителя в качестве аргумента:

-(IBAction)buttonPressed:(id)theButton 
{ 
    NSLog("Button %d pressed",[theButton tag]); 
} 
Смежные вопросы