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 12-16-2011, 07:26 PM   #1 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 63
CanDev is on a distinguished road
Default table not showing up properly

Hi,

I get my table to show up, but the info isnt populated properly.

The cell just shows the text i have put in as a placeholder and not what is in my plist.

this works

Code:
    - (void)viewDidLoad
    {
        [super viewDidLoad];

        if (CurrentLevel == 0) {
            NSMutableArray *array = [[NSMutableArray alloc] init];
            self.bandList = array;
           
            AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
            self.bandList = [appDelegate.data objectForKey:@"Rows"];
            self.navigationItem.title = @"2012 Competing Bands";
        }
        else
            self.navigationItem.title = CurrentTitle;
    }
this works

Code:
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        // Return the number of sections.
        return 1;
    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        // Return the number of rows in the section.
        return [bandList count];
    }
this partially works, the images that show up are correct but the title and description dont show

Code:
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        TableCell *cell = (TableCell *)[tableView dequeueReusableCellWithIdentifier:@"BandCell"];
       
        // Configure the cell...
        NSDictionary *dict = [self.bandList objectAtIndex:indexPath.row];
        cell.nameLabel.text = [dict objectForKey:@"Title"];
        cell.countryLabel.text = [dict objectForKey:@"Description"];
        UIColor *color = ((indexPath.row % 2) == 0) ? [UIColor colorWithRed:0/255 green:0/255 blue:0/255 alpha:1] : [UIColor blackColor];
        cell.nameLabel.textColor = color;
       
        //adding image to cell
       
        if ([dict objectForKey:@"imageKey"] == nil) {
            return cell;
           
        } else {
            NSString *path = [[NSBundle mainBundle] pathForResource:[dict objectForKey:@"imageKey"] ofType:@"png"];
            UIImage *theImage = [UIImage imageWithContentsOfFile:path];
            cell.imageView.image = theImage;
            theImage = cell.bandImage.image;
            theImage = nil;
        }
        return cell;
    }
Here is the table Cell file

Code:
    //  TableCell.h

    #import <UIKit/UIKit.h>

    @interface TableCell : UITableViewCell

    @property (nonatomic, strong) UILabel *nameLabel;
    @property (nonatomic, strong) UILabel *countryLabel;
    @property (nonatomic, strong) UIImageView *bandImage;

    @end


Code:
    //  TableCell.m

    #import "TableCell.h"

    @implementation TableCell
    @synthesize nameLabel, countryLabel, bandImage;

    - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
    {
        self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
        if (self) {
            // Initialization code
        }
        return self;
    }

    - (void)setSelected:(BOOL)selected animated:(BOOL)animated
    {
        [super setSelected:selected animated:animated];

        // Configure the view for the selected state
    }

    @end

I am sure i am missing something simple. I had it working before i made a custom cell but now its not. I am using a custom cell because I want the image to be there too. Can I have an image if I choose the title/subtitle cell?

Thanks for your help

CanDev
CanDev is offline   Reply With Quote
Old 12-17-2011, 08:15 AM   #2 (permalink)
Registered Member
 
Naughty_Ottsel's Avatar
 
Join Date: Aug 2008
Location: Gillingham, Dorset, UK
Age: 19
Posts: 218
Naughty_Ottsel is on a distinguished road
Send a message via MSN to Naughty_Ottsel
Default

How have you made the cells? Using a xib or just in code.

if it is in code you will need to so something along the lines of:

Code:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
    {
        self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
        if (self) {
            self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, 150, 50)];
self.countryLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 15, 150, 25)];

//Any additional set up code of the label e.g. fonts, colors etc
        }
        return self;
    }
__________________
Follow me on Twitter
Naughty_Ottsel is offline   Reply With Quote
Old 12-17-2011, 11:59 AM   #3 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 63
CanDev is on a distinguished road
Default

Quote:
Originally Posted by Naughty_Ottsel View Post
How have you made the cells? Using a xib or just in code.

if it is in code you will need to so something along the lines of:

Code:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
    {
        self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
        if (self) {
            self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, 150, 50)];
self.countryLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 15, 150, 25)];

//Any additional set up code of the label e.g. fonts, colors etc
        }
        return self;
    }
Made the cell in storyboard. Turns out I forgot to add the IBOutlets to the TableCell.h file. OOPS!!

Thats all working now that I did that.

Thanks for the reply though
CanDev is offline   Reply With Quote
Reply

Bookmarks

Tags
table cell, tableview, tableview cell, 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: 400
13 members and 387 guests
7twenty7, AppsBlogger, Creativ, Dalia, David-T, Duncan C, HemiMG, heshiming, LunarMoon, Murphy, pbart, teebee74, Tomsky
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,915
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

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