Quote:
Originally Posted by gtyt38
Hi everyone,
I am looking for a way to switch the data for a UITableView when the value of a UISegmentedControl is changed. I would very much appreciate any help (and sample code, preferably)!
|
Create a table view controller. A table view controller is a subclass of UIViewController.
In IB, create a view that contains a table view and a segmented control.
Set up an action and outlet in your view controller for the segmented control.
Connect the action to the value changed event for the segmented control.
In your IBAction, write code that does whatever you need it to do when the value of the segmented control changes.
No, I don't have any sample code for you because your needs are unique.
You don't make it clear what you mean by "change the data". Do you want to display completely different sets of data depending on the setting of the segmented control?
In that case, store your sets of data in an NSArray, where index 0 in the array holds the data you want to display for the first setting on the segmented control, index 1 holds the data for the second setting on the control, index 2 holds the data for the third setting, etc. Then, when the user switches the segmented control, call the table view's reloadData method and the table view will ask the data source for its data, and you can supply data from a different dataset.