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 07-16-2011, 04:27 PM   #1 (permalink)
Mobile Apps Developer
 
JoeRCruso's Avatar
 
Join Date: Oct 2010
Posts: 24
JoeRCruso is on a distinguished road
Default How Do I Change a Table View Cell's Subtitle?

Hello. I have a problem that is making me go crazy. Everything I try doesn't work, and I'm not sure what I'm doing wrong. Basically, I'm trying to let the user change the subtitle in all of the table view cells. They just press a button and it would change them. So I tried to do this by setting the NSMutableArray to have different objects. I've tried addObject, replaceObjectAtIndex, and even removeAllObjects. None of them seem to have any effect. So... What should I try?
JoeRCruso is offline   Reply With Quote
Old 07-16-2011, 04:53 PM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

You aren't really expecting a good answer from this, are you?
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 07-16-2011, 04:57 PM   #3 (permalink)
Mobile Apps Developer
 
JoeRCruso's Avatar
 
Join Date: Oct 2010
Posts: 24
JoeRCruso is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
You aren't really expecting a good answer from this, are you?
I dunno. You want some sample code or something? I thought this was somewhat easy to understand. Could be wrong though.
JoeRCruso is offline   Reply With Quote
Old 07-16-2011, 04:58 PM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Need to know what you are doing in order to provide a correction.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 07-16-2011, 06:14 PM   #5 (permalink)
Mobile Apps Developer
 
JoeRCruso's Avatar
 
Join Date: Oct 2010
Posts: 24
JoeRCruso is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
Need to know what you are doing in order to provide a correction.
When the user taps a button, I want to change the all of the table view cells' subtitles. The table view only has 4 cells.

In the .h I have:

Code:
#import <UIKit/UIKit.h>

@interface MyViewController : UIViewController <UIActionSheetDelegate> {
    
    IBOutlet UINavigationController *mainNavCont;
    
    IBOutlet UITableView *tableView;
    NSMutableArray *data;
    NSMutableArray *subTitleData;
}

- (IBAction)button:(id)sender;

@end
In the .m, I have:

Code:
#import "MyViewController.h"

@implementation MyViewController

- (IBAction)button:(id)sender {
    [subTitleData removeObject:@"5 mins"];
    [subTitleData removeObject:@"10 mins"];
    [subTitleData removeObject:@"15 mins"];
    [subTitleData removeObject:@"20 mins"];
    [subTitleData addObject:@"10 mins"];
    [subTitleData addObject:@"15 mins"];
    [subTitleData addObject:@"20 mins"];
    [subTitleData addObject:@"25 mins"];
    [tableView reloadData];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return [data count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *cellID = @"Cell";
        
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Cell"] autorelease];
        }
        cell.textLabel.text = [data objectAtIndex:indexPath.row];
        cell.detailTextLabel.text = [subTitleData objectAtIndex:indexPath.row];
        
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        
        return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
        
        if (indexPath.row == 0) {
           //haven't gotten to these yet
        }
        if (indexPath.row == 1) {
            
        }
        if (indexPath.row == 2) {
            
        }
        if (indexPath.row == 3) {
            
        }
    }

- (void)dealloc {
    [mainNavCont release];
    [tableView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
        
    data = [[NSMutableArray alloc] initWithObjects:@"First", @"Second", @"Third", @"Fourth", nil];
    subTitleData = [[NSMutableArray alloc] initWithObjects:@"5 mins", @"10 mins", @"15 mins", @"20 mins", nil];
}

- (void)viewDidUnload {
    [mainNavCont release];
    mainNavCont = nil;
    [tableView release];
    tableView = nil;
    [super viewDidUnload];
}

@end
Not sure what I'm doing wrong. The subtitles don't change when I tap the button.
JoeRCruso is offline   Reply With Quote
Old 07-16-2011, 06:19 PM   #6 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Put an NSLog in the method to make sure it's firing and check the connection on your tableview outlet.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 07-16-2011, 06:28 PM   #7 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Also (probably not related), having a navigation controller in your view controller is probably the wrong thing to be doing.

Since this isn't the best way to set up your data, you should perhaps consider replacing the objects, rather than removing-and-then-adding.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 07-16-2011, 06:40 PM   #8 (permalink)
Mobile Apps Developer
 
JoeRCruso's Avatar
 
Join Date: Oct 2010
Posts: 24
JoeRCruso is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
Also (probably not related), having a navigation controller in your view controller is probably the wrong thing to be doing.

Since this isn't the best way to set up your data, you should perhaps consider replacing the objects, rather than removing-and-then-adding.
I have tried replacing them using replaceObjectAtIndex, but I cannot use indexPath as the index. I tried just throwing a random number (0) in there, and that didn't work either.
JoeRCruso is offline   Reply With Quote
Old 07-16-2011, 06:43 PM   #9 (permalink)
Mobile Apps Developer
 
JoeRCruso's Avatar
 
Join Date: Oct 2010
Posts: 24
JoeRCruso is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
Put an NSLog in the method to make sure it's firing and check the connection on your tableview outlet.
I have used NSLog and it is firing. I just check the connection and it's connected too.
JoeRCruso is offline   Reply With Quote
Old 07-16-2011, 06:46 PM   #10 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Put this at the end of your IBAction method:
Code:
NSLog(@"%@", subTitleData);
and paste the result here.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 07-16-2011, 06:57 PM   #11 (permalink)
Mobile Apps Developer
 
JoeRCruso's Avatar
 
Join Date: Oct 2010
Posts: 24
JoeRCruso is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
Put this at the end of your IBAction method:
Code:
NSLog(@"%@", subTitleData);
and paste the result here.
I figured out the issue. It was a simple typo. I spelt subTitleData wrong. I copied it correct though haha. Sorry for wasting your time :/
JoeRCruso is offline   Reply With Quote
Old 07-16-2011, 09:46 PM   #12 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Wouldn't that cause a compiler error that would say something like undefined pointer?
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 07-16-2011, 09:48 PM   #13 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Quote:
Originally Posted by JoeRCruso View Post
I have tried replacing them using replaceObjectAtIndex, but I cannot use indexPath as the index. I tried just throwing a random number (0) in there, and that didn't work either.
You only have 1 section, so use the row as the index.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Reply

Bookmarks

Tags
cell, nsmutablearray, table, uitableview, view

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: 402
17 members and 385 guests
blasterbr, buggen, Clouds, dre, EvilElf, HemiMG, jeroenkeij, jimmyon122, jonathandeknudt, LEARN2MAKE, Mah6447, n00b, nyoe, pungs, Sami Gh, stanny, toon4413
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,668
Threads: 94,121
Posts: 402,900
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jonathandeknudt
Powered by vBadvanced CMPS v3.1.0

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