在 uitextfield 中使用 UITableViewCellAccessoryDe​​tailButton

Use UITableViewCellAccessoryDetailButton in uitextfield

我有一个 UITextField,它需要在其右视图中显示一个按钮。

如何加载与 UITableViewCellAccessoryDe​​tailButton 中使用的信息图标具有相同图像的按钮?

正如 Rory McKinnel 在评论中解释的那样,解决方案是:

UIButton *button=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];

//说这是你的文本字段

UITextField *txt = [[UITextField alloc]init];

//这是添加信息按钮的方式

UIButton *yourButton = UIButton *button=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[yourButton addTarget:self action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];
txt.rightView = yourButton;
txt.rightViewMode = UITextFieldViewModeAlways;
[self.view addSubview:txt];