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-29-2011, 09:39 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 1
L-1987 is on a distinguished road
Default Custom UITableViewCell to display varying images/strings based on NSDictionary

I have a custom UITableViewCell class and would like to display images and strings linearly. For example:

Row 1: [Image1] string1 [Image2] string2 [Image3]

Row 2: [Image4] string3 [Image5]

The images have varying widths but I would like equal spacing. The amount of images and strings on each row also vary.

I've created a CustomCell class and I need to be able adjust the dimensions of the subviews and CGRectMake based on the containing images/text that are referenced in my NSDictionary. (See below).

Setting up my CustomCell class for passing of this data is where I'm stuck.

Thanks for the help.



My CustomCell class:

Code:
    #import "CustomCell.h"
    
    
    @implementation CustomCell
    
    @synthesize primaryLabel,secondaryLabel,image1;
    
    
    -  (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
        if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
            // Initialization code
            primaryLabel = [[UILabel alloc]init];
            primaryLabel.textAlignment = UITextAlignmentLeft;
            primaryLabel.font = [UIFont systemFontOfSize:16];
            secondaryLabel = [[UILabel alloc]init];
            secondaryLabel.textAlignment = UITextAlignmentLeft;
            secondaryLabel.font = [UIFont systemFontOfSize:14];
            image1 = [[UIImageView alloc]init];
            
            [self.contentView addSubview:primaryLabel];
            [self.contentView addSubview:secondaryLabel];
            [self.contentView addSubview:image1];

        }
        return self;
    }
    
    - (void)layoutSubviews {
        [super layoutSubviews];
        CGRect frame;
        frame= CGRectMake(0 ,5, 200, 25);
        primaryLabel.frame = frame;
        
        frame= CGRectMake(0 ,30, 200, 25);
        secondaryLabel.frame = frame;

        frame= CGRectMake(0, 60, 23, 20);
        image1.frame = frame;
...

My RootViewController


Code:
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        
        static NSString *CellIdentifier = @"Cell";
        
        CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
        
        // Set up the cell...
    	NSDictionary *dictionary = nil;
    
    
    //Search
    	if (tableView == self.searchDisplayController.searchResultsTableView)
    	{
            dictionary = [self.filteredListContent objectAtIndex:indexPath.row];
        }
    	else
    	{
            dictionary = [self.tableDataSource objectAtIndex:indexPath.row];
        }
        
        
    //Original
        cell.primaryLabel.text = [dictionary objectForKey:@"Title"];    

        
        for (NSArray *keystroke in [dictionary objectForKey:@"Strokes"]) {
            
    
               for (int i = 0; i < 2; i++) {
               
            
                   if ([(NSString *)keystroke isEqualToString:@"string1"] || [(NSString *)keystroke isEqualToString:@"string2"]) {
                     cell.secondaryLabel.text = (NSString *)keystroke; 
                     }

                   else { 
                NSString *imageFilePath = [NSString stringWithFormat:@"%@.png", keystroke];
                NSLog(@"%@", imageFilePath);
                UIImage *myimage = [UIImage imageNamed:imageFilePath];

                    cell.image1.image = myimage;
                
            }
            }
        }
        return cell;
    
        
    }
...
L-1987 is offline   Reply With Quote
Reply

Bookmarks

Tags
cgrect, nsdictionary, uitableview, uitableviewcell

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: 391
6 members and 385 guests
JackReidy, jeroenkeij, Sami Gh, yomo710, Yosh_K
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,671
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, JackReidy
Powered by vBadvanced CMPS v3.1.0

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