gpt4 book ai didi

ios - 如何将UIButton的名称保存在字符串中?

转载 作者:行者123 更新时间:2023-12-01 17:12:52 25 4
gpt4 key购买 nike

我有一个名为的按钮

UIButton *button1;

如何将'button1'保存为字符串?还是我可以保存它?

最佳答案

检查一下

进口

#import "objc/runtime.h"


-(IBAction)btnItemListClicked:(id)sender

{
UIButton *btn=sender;
NSString *name = nil;

uint32_t ivarCount;
Ivar *ivars = class_copyIvarList([self class], &ivarCount);

if(ivars)
{
for(uint32_t i=0; i<ivarCount; i++)
{
Ivar ivar = ivars[i];

id pointer = object_getIvar(self, ivar);
if(pointer == sender)
{
name = [NSString stringWithUTF8String:ivar_getName(ivar)];
break;
}
}

free(ivars);
}
NSLog(@"%@", name);
}

输出为:

姓名印刷说明:

btnconferenceCall

检查此示例演示

ButtonDemo

关于ios - 如何将UIButton的名称保存在字符串中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18328981/

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