Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-22-2010, 05:45 PM   #1 (permalink)
gtyt38
 
Join Date: Apr 2010
Location: Baltimore, MD, USA
Posts: 61
gtyt38 is on a distinguished road
Default UISegmentedControl and UITableView

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)!
__________________
No animals were injured in the creation of this post…however, a few electrons were mildly inconvenienced…
gtyt38 is offline   Reply With Quote
Old 08-22-2010, 09:42 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by gtyt38 View Post
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.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 08-23-2010, 08:01 AM   #3 (permalink)
gtyt38
 
Join Date: Apr 2010
Location: Baltimore, MD, USA
Posts: 61
gtyt38 is on a distinguished road
Default

Thank you very much, but what I need is how to change the table's data source from array1 to array2.
__________________
No animals were injured in the creation of this post…however, a few electrons were mildly inconvenienced…
gtyt38 is offline   Reply With Quote
Old 10-13-2010, 06:52 AM   #4 (permalink)
Registered Member
 
Jules2010's Avatar
 
Join Date: Apr 2010
Location: UK
Posts: 157
Jules2010 is on a distinguished road
Default

I'm trying to do this two, but switching the data isn't a problem as I'm using the same code and just changing my sql.

However, when I add my segmented control to my view, and resize my table view down a little, I can't see my segmented control when my app runs.

I've tried hiding my navigation bar just in case its hidden behind, but the table view occupies the full view.

Any ideas ?

Jules2010 is offline   Reply With Quote
Old 10-13-2010, 07:41 AM   #5 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Jules2010 View Post
I'm trying to do this two, but switching the data isn't a problem as I'm using the same code and just changing my sql.

However, when I add my segmented control to my view, and resize my table view down a little, I can't see my segmented control when my app runs.

I've tried hiding my navigation bar just in case its hidden behind, but the table view occupies the full view.

Any ideas ?

I bet you have a navigation bar and/or status bar in your app, but haven't made room for one in IB. In that case, the system will resize the table view and shift things around in order to make room for the bar(s).

Your segmented control is probably being hidden under the nave bar.

Set up the view in IB to have a status bar and/or nav bar if it will be used with those elements. That way you can lay out your views correctly. (there is a popup in IB (on the first inspector page, if memory serves) that tells IB if the view should include a nav bar or status bar.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 11-15-2010, 09:06 AM   #6 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 5
fbartolom is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
I bet you have a navigation bar and/or status bar in your app, but haven't made room for one in IB. In that case, the system will resize the table view and shift things around in order to make room for the bar(s).

Your segmented control is probably being hidden under the nave bar.

Set up the view in IB to have a status bar and/or nav bar if it will be used with those elements. That way you can lay out your views correctly. (there is a popup in IB (on the first inspector page, if memory serves) that tells IB if the view should include a nav bar or status bar.
I have both a navigation controller and a tabbar and I do not find any way to have the segmented control show up without inserting it in the header of the table, what is not very practical given the segmented control is used to sort the table. Any suggestion?
fbartolom is offline   Reply With Quote
Reply

Bookmarks

Tags
datasource, uisegmentedcontrol, uitableview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 338
5 members and 333 guests
freewind, HemiMG, lendo, Newbie123, PlutoPrime
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,894
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:55 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0