基于SegmentedControl有条件地重新加载UITableView
当点击按钮时,我想根据分段控件的值有条件地重新加载表格视图。
因此,在我的 buttonTapped 方法中,我有这段代码随机选择一个数组项。在 else
块中,我想从数组中删除选定的项目,以防止再次选择相同的项目,目前我从数组中删除它......
但我希望能够返回应用程序恢复到点击按钮之前的状态,也许可以通过创建数组的 -mutableCopy
,然后从中删除项目。
我必须有哪些潜在选项来指示无法再次选择某个项目?变灰了?颜色改变?删除行?
if (selectionControl.selectedSegmentIndex == 0) {
int r = arc4random() % [[[APP_DELEGATE itemsDictionary] objectForKey:category] count];
NSLog(@"%i",[[[APP_DELEGATE itemsDictionary] objectForKey:category] objectAtIndex:r]);
} else {
//copyOfArray = [APP_DELEGATE.....]mutableCopy]; // Maybe?
int r = arc4random() % [[[APP_DELEGATE itemsDictionary] objectForKey:category] count];
NSLog(@"%i",[[[APP_DELEGATE itemsDictionary] objectForKey:category] objectAtIndex:r]);
}
[[[APP_DELEGATE itemsDictionary] objectForKey:category] removeObjectAtIndex:r];
//[copyOfArray removeObjectAtIndex:r]; // Maybe?
[self.tableView reloadData];
}
在每个 tableView 方法中,我需要在从 APP_DELEGATE 或副本返回值之前检查选择控件的状态。
谢谢。
I would like to reload a table view conditionally based on the value of a segmented control, when a button is tapped.
So in my buttonTapped method, i have this code which randomly selects an array item. In the else
block i would like to remove the selected item from the array to prevent the same item being selected again, currently I remove it from the array...
But i would like the ability to return the app to the state before the button was tapped, perhaps by making a -mutableCopy
of the array and then removing the item from that.
What potential options do i have to indicate that an item cannot be selected again? Grayed out? Color change? Remove row?
if (selectionControl.selectedSegmentIndex == 0) {
int r = arc4random() % [[[APP_DELEGATE itemsDictionary] objectForKey:category] count];
NSLog(@"%i",[[[APP_DELEGATE itemsDictionary] objectForKey:category] objectAtIndex:r]);
} else {
//copyOfArray = [APP_DELEGATE.....]mutableCopy]; // Maybe?
int r = arc4random() % [[[APP_DELEGATE itemsDictionary] objectForKey:category] count];
NSLog(@"%i",[[[APP_DELEGATE itemsDictionary] objectForKey:category] objectAtIndex:r]);
}
[[[APP_DELEGATE itemsDictionary] objectForKey:category] removeObjectAtIndex:r];
//[copyOfArray removeObjectAtIndex:r]; // Maybe?
[self.tableView reloadData];
}
In each of the tableView methods i would need to check the state of the selectionControl before returning the value from either the APP_DELEGATE or the copy.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我要做的是访问 UITableCellView 的“textLabel”成员,并将文本颜色设置为灰色。
您可以实现 tableView:willSelectRowAtIndexPath: 以在按下该行时返回 NIL - 这将使该行实际上无法被选择。
I think what I'd do is access the "textLabel" member of the UITableCellView, and set the text color to grey.
You can them implement tableView:willSelectRowAtIndexPath: to return NIL when that row is pressed - which will make it so that row cannot actually be selected.