我们可以使用 initWithNibName 在不同的视图中重用相同的 .xib 文件吗?
我有一个 UITableView,其中包含 8 个项目(静态)。现在,当我单击 8 个单元格中的每一个时,每个单元格都包含 1 个单独的控件。
例如:
单击单元格 1:使用 UIPickerView 的新视图。
单击单元格 2:使用 UIDatePicker 的另一个视图
单击单元格 3:使用 UITextField 的另一个视图。 。 ...等等。
我可以仅使用一个包含所有控件的 .xib 文件吗,但是当我单击该单元格时,只有该控件可见,所有其他控件都隐藏。
我还希望这些控件值应该返回到表格单元格的详细文本。
如何重复使用一个 .xib 文件?我可以使用不同的 nib 名称调用 xib 文件并签入 initwithnibname 方法吗?
请你给我一个很好的例子......
I have a UITableView which contains 8 items (static). Now when i click each of 8 cells then each cell contains 1 single control.
For example:
Click cell 1: New view with UIPickerView.
Click cell 2: Another view with UIDatePicker
Click cell 3: One more view with UITextField.
.
... so on.
Can I use only one .xib file which contains all the controls but when i click that cell only that control is visible and all other are hidden.
Also i want that those controls value should be return to detailText of Table Cell.
How can I reuse one .xib file?? can i invoke xib file with different nib names and check in initwithnibname method??
please can u give me good example for this....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基本上,我找到的唯一方法是设置条件语句,其中仅显示特定条件下的某些控件,并隐藏其他控件,在其他条件下类似。
我认为这是您可以根据同一 XIB 中的单元格选择显示不同控件的唯一方法。
希望这对您有帮助。
编辑:
您可以使用标志(在应用程序委托中声明)并根据所选单元格在 didSelectRowAtIndexPath 方法中设置标志。
现在,在 PickerView 的 viewDidLoad 上,您可以检查相同的标志,它可以让您知道单击了哪个单元格。
希望这对您有帮助。
EDIT-1
您可以只使用如图所示的 NSUserDefaults..
对于 Cell-1
对于 Cell-2:
对于 Cell-3:
等等..
希望这现在可以帮助您
Basically the only way I find is to set conditional statements where in you show only some of the controls in a particular condition and hide the others and in other conditions similarly.
I think this is the only way you can show different controls based on cell selection in same XIB.
Hope this helps you.
EDIT:
You can use a flag (declared in application delegate) and set the flag in didSelectRowAtIndexPath method based on the cell selected.
Now on the viewDidLoad of the PickerView, you can check the same flag which would let you know which cell was clicked.
Hope this helps you.
EDIT-1
You can just use the NSUserDefaults as shown..
For Cell-1
For Cell-2:
For Cell-3:
and so on..
Hope this helps you now
我有一个在首选项屏幕上使用通用笔尖文件的绝妙想法,所以我有一个“切换笔尖”、一个“文本字段笔尖”和一个“文本笔尖”。我将控件分配为在
cellForRowAtIndexPath
中以编程方式查看控制器属性。然而,由于某种神秘的原因,这最终没有发挥作用。我最终为每个单元设计了一个定制笔尖。有用。然后,在 cellForRowAtIndexPath 中,我必须确定加载了哪个单元格,以将控件初始化为正确的值。
I had this brilliant idea of using generic nib files on a Prefs screen, so I had a "switch nib", a "text field nib", and a "text nib". I assigned the controls to view controller properties programmatically in the
cellForRowAtIndexPath
. However, this ended up not functioning for some mysterious reason.I ended up designing a custom nib for each cell. It works. Then, in the
cellForRowAtIndexPath
I have to determine which cell was loaded, to initialize the control to the proper value.