gpt4 book ai didi

iphone - 在其点击事件中获取按钮标题

转载 作者:行者123 更新时间:2023-11-28 20:41:49 25 4
gpt4 key购买 nike

                for (int i = 0; i < ABMultiValueGetCount(emails)  ; i++)
{

CFStringRef email = ABMultiValueCopyValueAtIndex(emails, i);
//CFStringRef emailType = ABMultiValueCopyLabelAtIndex(emails, i);
emailString = (NSString *)email;
//emailTypeString = (NSString *)emailType;

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(15, 320 - x, 290, 40);
[button setTitle:emailString forState:UIControlStateNormal];
button.titleLabel.font = [UIFont fontWithName:@"Helvetica Bold" size:18];
[button addTarget:self action:@selector(OnEmailIdSelection:) forControlEvents:UIControlEventTouchUpInside];
[self.selectEmailId addSubview:button];
x = x+70;
}


}

我有上面的代码,其中有一个按钮单击事件 OnEmailIdSelection。在此事件中,我想将发件人的标题(即单击按钮的标题)放入字符串变量中。

最佳答案

试试这个:

-(void) OnEmailIdSelection:(id)sender
{
if ([sender isKindOfClass:[UIButton class]])
{
UIButton *button = (UIButton*)sender;
NSString *title = button.currentTitle;

// do whatever you want with title
}
}

关于iphone - 在其点击事件中获取按钮标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8226321/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com