使用 UIPickerView 的选定行来确定要添加到哪个数组
因此,我设置了一个 UIPickerView 来根据选择的组件显示不同的 UITableView 数据。该表由数组填充,而 pickerview 基本上只是告诉表要使用哪个数组。
我希望用户能够向每个单独的数组添加信息,从而更改每个单独的表格视图。但是,我在访问我创建的 IBAction 中的 PickerView 行时遇到了一些问题。
我有一个“添加”按钮,它调用 IBAction 将用户输入添加到数组中。我遇到麻烦的地方是告诉操作将输入添加到哪个数组。
。
-(IBAction)postToWall:(id)sender {
[userInput resignFirstResponder];
NSString *userInputString;
userInputString=userInput.text;
[otherPosts addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:userInputString,@"post", @"Jeff.png",@"picture",nil]];
[wallTable reloadData];
[userInput setText:@" "];
[sendButton setEnabled:NO];
”
我的直觉是添加一个 If 语句,它基本上表示“如果 pickerview 行为 0,则添加到此数组”和“如果 pickerview 行为 1,则添加到该数组 这可能吗?我如何与 pickerview 对话并设置 if 语句?抱歉,我对这一切有点陌生。
谢谢大家真的很感激!
So I've set up a UIPickerView to display different UITableView Data depending on which component is selected. The table is populated by arrays, and the pickerview basically just tells the table which array to use.
I want the user to be able to add info to each individual array and thus change each individual tableview. However, im having a little trouble accessing the PickerView row within the IBAction i've created.
I have a "add" button that calls an IBAction that adds the user input to the array. Where I am having trouble is telling the action which array to add the input to.
this is what I have so far:
-(IBAction)postToWall:(id)sender {
[userInput resignFirstResponder];
NSString *userInputString;
userInputString=userInput.text;
[otherPosts addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:userInputString,@"post", @"Jeff.png",@"picture",nil]];
[wallTable reloadData];
[userInput setText:@" "];
[sendButton setEnabled:NO];
}
My intuition is to add an If statement, which basically says "if pickerview row is 0, then add to this array," and "if pickerview row is 1, then add to that array." Is this possible? How do I talk to the pickerview and set up that if statement? Sorry im a little new to all this.
Thanks guys really appreciate it!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的建议是,
创建一个适用于表视图数据源的数组。当您选择为显示和调用数据源而创建的选择器的任何行时,意味着类似这样的事情,
在 .h 中声明一个数组
,使其属性并合成它
并在viewDidLoad中分配它并释放它dealloc。
并在选择器视图委托中
My suggetion is,
Make a single array which works data source for your table view.When you select any row of picker your array created for showing and call data source means some thing like this,
declare a array in .h
make it property and synthesize it
and alloc it in viewDidLoad and release it dealloc.
and in picker View delegate
如果我是你,我只需将 currentArray 变量添加到我的代码中,并在每次 PickerView 更改值时将各个数组设置为此 currentArray。
并使用 [currentArray addObject: ];在你的 -(IBAction)postToWall:(id)sender 方法中
if I were you I just add currentArray variable to my code and set your individual arrays to this currentArray every time when my PickerView changed value.
and use [currentArray addObject: ]; in your -(IBAction)postToWall:(id)sender method