点击表格行时显示警报视图
我有一个包含字符串列表的表视图,如下所示:
String1
String2
String3
String4
我想将其中一个设置为默认值,即当用户点击“String3”时,应该弹出一个警报视图,询问他们是否想要将该项目设置为默认值。
我将如何在我的表视图控制器中实现此警报视图?
I have a table view with a list of strings as follows:
String1
String2
String3
String4
I want to make one of these the default, i.e., when the user taps "String3", an alert view should pop up asking if they want to make that item the default.
How would I implement this alert view in my table view controller?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您需要定义一个实例变量来跟踪当前选择的字符串。在你的头文件中类似这样的东西就可以了。
接下来,在 tableView:didSelectRowAtIndexPath: 委托方法中创建一个警报视图。
要在用户点击警报中的按钮后保存值,您应该使用 UIAlertView 委托。
First you'll want to define an instance variable to keep track of the string that's currently selected. Something like this in your header file will be fine.
Next, in your tableView:didSelectRowAtIndexPath: delegate method create an alert view.
To save the value after the user taps a button in the alert you should use the UIAlertView delegate.
我没有足够的声誉在这里发表评论。但你的 if 语句应该是:
也就是说,当单击 yes 按钮时,你是否想做某事。不管怎样,感谢您的快速教程,除了那个轻微的打字错误之外,它运行得很好。
I don't have enough reputation to comment here. But your if statement should be:
That is to say if you want to do something when the yes button is clicked. Anyways, thanks for the quick tutorial, and apart from that slight typo it worked perfectly.