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 > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 11-20-2011, 04:59 AM   #1 (permalink)
Registered Member
 
Join Date: Nov 2011
Location: Singapore
Posts: 6
Joseph83 is on a distinguished road
Default UISwitch (on/off) to show and hide UITableView

Just wonder if it's possible to have UISwitch (ON/OFF) to show/hide the UITableView. For example:

There are 3 sections (Section 0,Section 1, Section 2) - cellForRowAtIndexPath

//it is for quantity (1 row) that redirects to another controller
if (indexPath.section == 0)
{

}

//it is for UISwitch (On/Off)
else if (indexPath.section == 1)
{
NSString *cellValue1 = [mealArray objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue1;
//NSLog(cell.textLabel.text);

switchview = [[[UISwitch alloc] initWithFrame:CGRectZero] autorelease];
cell.accessoryView = switchview;

[(UISwitch *) cell.accessoryView addTarget: self action: @selector(checkState forControlEvents: UIControlEventValueChanged];
}

//it is for Section 2 (if switch ON then display Section 2 otherwise hide section 2)
else
{
NSString *cellValue2 = [numberArray objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue2;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
}

//UISwitch Action (On/Off)
- (IBAction) checkState: (id) sender {
if (switchview.on)
{
[tableNum setHidden:NO];
[tableNum reloadData];
NSLog(@"Switched ON yeah");
}

else {
[tableNum setHidden:YES];
//[tableNum reloadData];
NSLog(@"Switched OFF yeah");
}
}

* I test NSLog and it is correct BUT I don't know why UITableView (tableNum) does not show/hide. Actually tableNum is a part of Section 0,1,2. Wonder if I have to create another UITableView for Section 2 only. I am confused.

It's similar to Settings - WIFI (ON/OFF) then display the list of SSID.

Please give me advice. Hope to hear from you soon!
Joseph83 is offline   Reply With Quote
Old 11-20-2011, 06:52 AM   #2 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 22
Krillere is on a distinguished road
Default

Please use the '[code]' and '[ /code]' tags for entering code. That's just confusing :P
Krillere is offline   Reply With Quote
Old 11-20-2011, 07:41 AM   #3 (permalink)
Registered Member
 
Join Date: Nov 2011
Location: Singapore
Posts: 6
Joseph83 is on a distinguished road
Default

Just wonder if it's possible to have UISwitch (ON/OFF) to show/hide the UITableView. For example:

There are 3 sections (Section 0,Section 1, Section 2) - cellForRowAtIndexPath

Code:
//it is for quantity (1 row) that redirects to another controller
if (indexPath.section == 0) 
{

}

//it is for UISwitch (On/Off)
else if (indexPath.section == 1)
{
NSString *cellValue1 = [mealArray objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue1;
//NSLog(cell.textLabel.text);

switchview = [[[UISwitch alloc] initWithFrame:CGRectZero] autorelease];
cell.accessoryView = switchview;

[(UISwitch *) cell.accessoryView addTarget: self action: @selector(checkState forControlEvents: UIControlEventValueChanged];
}

//it is for Section 2 (if switch ON then display Section 2 otherwise hide section 2)
else
{
NSString *cellValue2 = [numberArray objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue2;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
}

//UISwitch Action (On/Off)
- (IBAction) checkState: (id) sender {
if (switchview.on)
{
[tableNum setHidden:NO];
[tableNum reloadData];
NSLog(@"Switched ON yeah");
}

else {
[tableNum setHidden:YES];
//[tableNum reloadData];
NSLog(@"Switched OFF yeah");
}
}
* I test NSLog and it is correct BUT I don't know why UITableView (tableNum) does not show/hide. Actually tableNum is a part of Section 0,1,2. Wonder if I have to create another UITableView for Section 2 only. I am confused.

It's similar to Settings - WIFI (ON/OFF) then display the list of SSID.

Please give me advice. Hope to hear from you soon!
Joseph83 is offline   Reply With Quote
Old 11-22-2011, 08:21 PM   #4 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,002
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Joseph83 View Post
Just wonder if it's possible to have UISwitch (ON/OFF) to show/hide the UITableView. For example:

There are 3 sections (Section 0,Section 1, Section 2) - cellForRowAtIndexPath

Code:
//it is for quantity (1 row) that redirects to another controller
if (indexPath.section == 0) 
{

}

//it is for UISwitch (On/Off)
else if (indexPath.section == 1)
{
NSString *cellValue1 = [mealArray objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue1;
//NSLog(cell.textLabel.text);

switchview = [[[UISwitch alloc] initWithFrame:CGRectZero] autorelease];
cell.accessoryView = switchview;

[(UISwitch *) cell.accessoryView addTarget: self action: @selector(checkState forControlEvents: UIControlEventValueChanged];
}

//it is for Section 2 (if switch ON then display Section 2 otherwise hide section 2)
else
{
NSString *cellValue2 = [numberArray objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue2;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
}

//UISwitch Action (On/Off)
- (IBAction) checkState: (id) sender {
if (switchview.on)
{
[tableNum setHidden:NO];
[tableNum reloadData];
NSLog(@"Switched ON yeah");
}

else {
[tableNum setHidden:YES];
//[tableNum reloadData];
NSLog(@"Switched OFF yeah");
}
}
* I test NSLog and it is correct BUT I don't know why UITableView (tableNum) does not show/hide. Actually tableNum is a part of Section 0,1,2. Wonder if I have to create another UITableView for Section 2 only. I am confused.

It's similar to Settings - WIFI (ON/OFF) then display the list of SSID.

Please give me advice. Hope to hear from you soon!

What do you mean tableNum "is part of Section 0,1,2"? That part of your post makes me think that you are totally lost.

If there is only one table view on the screen, you should only have one table view in your program. You should not have a separate table view object for some sections but not others.


Where is tableNum declared? Is it of type UITableView* ?

How is it connected to your table view? Is it an outlet? Is it an instance variable that you set at runtime?

My guess is that tableNum is nil.

Change your log statements to show the value of tableNum:

Code:
NSLog(@"tableNum = %@. Set hidden = FALSE", tableNum);
__________________
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
Reply

Bookmarks

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: 411
13 members and 398 guests
bignoggins, djqbert, epaga, flamingliquid, jcdevelopments, leighec68, LunarMoon, markolo, mrtdmb, omagod, pinacate, revg, taylor202
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,645
Threads: 94,111
Posts: 402,861
Top Poster: BrianSlick (7,990)
Welcome to our newest member, leighec68
Powered by vBadvanced CMPS v3.1.0

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