Can Someone Look At My Code?

Discussion in 'iOS Programming' started by loon3y, Feb 29, 2012.

  1. macrumors 65816

    loon3y

    Joined:
    Oct 21, 2011
    #1
    and tell me whats wrong, the thing is it worked the first time around,

    and it said my code was deprecated, so i changed it to a more recent method and now it doesnt work at all, even if i changed back to my old code.


    can someone tell me wants wrong???





    Code:
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"Cell";
        
        CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil)
        {
            
            // Below is old way, retired method
            cell = [[[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
            
            
            // below is the new method, but doesnt work.
    //         cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        }
        
        // Set up the cell
        
        switch (indexPath.row)
        {
            case 0:
                cell.primaryLabel.text = @"Meeting on iPhone Development";
                cell.secondaryLabel.text = @"Sat 10:30";
                cell.myImageView.image = [UIImage imageNamed:@"1Star.png"];
                break;
            case 1:
                cell.primaryLabel.text = @"Call With Client";
                cell.secondaryLabel.text = @"Planned";
                cell.myImageView.image = [UIImage imageNamed:@"I_see_what_you_did_there_super.png"];
                break;
            case 2:
                cell.primaryLabel.text = @"Appointment with Joey";
                cell.secondaryLabel.text = @"2 Hours";
                cell.myImageView.image = [UIImage imageNamed:@"backgroun2.png"];
                break;
                default:
                break;
        }
        return cell;
    }
    
    
    
    
     
  2. macrumors regular

    Joined:
    Jun 29, 2006
    #2
    Are you using ARC? If so, it won't like the autorelease at the end. Try removing that and see if it starts working!
     
  3. macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #3
    A description of how this isn't working might also be helpful.
     
  4. thread starter macrumors 65816

    loon3y

    Joined:
    Oct 21, 2011
    #4
    no I'm not using ARC (even though i should)


    but I've tried removing regardless on both sets of code, and it still doesnt show up.


    I'm thinking about making the whole viewcontorller from scratch again,


    but the weird thing is, that the cells that are supposed to be populated are selectable (i can highlight them) but they just don't show the labels or images I've setup

    ----------




    the cells that are supposed to be there are selectable, but just nothing shows up.


    i just put dummy data in there for tests, I'm eventually going to make the table view show many categories for like a catalog type of thing.
     
  5. macrumors regular

    Joined:
    Jun 29, 2006
    #5
    If the cells are there, but the data isn't showing up I would check to make sure your custom cells are configured properly. If you didn't mean to use custom cells, change it to UITableViewCell.

    I'm assuming you did mean to use custom cells with how you are configuring them, so check to make sure your outlets for the labels and image views are set up properly. If I had to guess, I would say the code you have listed is working, but the code not shown, the custom cell code is the culprit. Check your outlets and it should work.
     
  6. thread starter macrumors 65816

    loon3y

    Joined:
    Oct 21, 2011
    #6


    yea, i ment to use custom cells as i learned it from a tutorial, it worked before, and it was done programmatically so i didn't have any IBOutlets, heres the code, but btw I'm using storyboards for nibs.



    Code:
    
    #import "CustomCell.h"
    
    @implementation CustomCell
    
    @synthesize primaryLabel, secondaryLabel, myImageView;
    
    - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
    {
        self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
        if (self) {
            // Initialization code
            primaryLabel = [[UILabel alloc]init];
            primaryLabel.textAlignment = UITextAlignmentLeft;
            primaryLabel.font = [UIFont systemFontOfSize:14];
            secondaryLabel = [[UILabel alloc]init];
            secondaryLabel.textAlignment = UITextAlignmentLeft;
            secondaryLabel.font = [UIFont systemFontOfSize:8];
            myImageView = [[UIImageView alloc]init];
            [self.contentView addSubview:primaryLabel];
            [self.contentView addSubview:secondaryLabel];
            [self.contentView addSubview:myImageView];
        }
    
        return self;
    }
    
    - (void)layoutSubviews {
        [super layoutSubviews];
        CGRect contentRect = self.contentView.bounds;
        CGFloat boundsX = contentRect.origin.x;
        CGRect frame;
        frame= CGRectMake(boundsX+10 ,0, 50, 50);
        myImageView.frame = frame;
        
        frame= CGRectMake(boundsX+70 ,5, 200, 25);
        primaryLabel.frame = frame;
        
        frame= CGRectMake(boundsX+70 ,30, 100, 15);
        secondaryLabel.frame = frame;
    }
    
    
    - (void)setSelected:(BOOL)selected animated:(BOOL)animated
    {
        [super setSelected:selected animated:animated];
    
        // Configure the view for the selected state
    }
    
    @end
    
    
    
     
  7. macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #7
  8. loon3y, Feb 29, 2012
    Last edited: Feb 29, 2012

    thread starter macrumors 65816

    loon3y

    Joined:
    Oct 21, 2011
    #8


    that way was actually the first way i set it up.


    but when it came to the coding and the structure in the app delegate, it got really screwed up because im having multiple custom cells, which is why i used that one ( or maybe i just didn't understand it correctly) can i use it n have multiple custom cells?

    like having each row be a category, like per say dresses, shirts, pants, shorts, etc etc, which would have a label and image, that would lead to another view controller. by pulling from a web service


    but heres the part that really got me clueless, i spend hours trying to make it work.




    Code:
    
    
    
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    	players = [NSMutableArray arrayWithCapacity:20];
    	Player *player = [[Player alloc] init];
    	player.name = @"Bill Evans";
    	player.game = @"Tic-Tac-Toe";
    	player.rating = 4;
    	[players addObject:player];
    	player = [[Player alloc] init];
    	player.name = @"Oscar Peterson";
    	player.game = @"Spin the Bottle";
    	player.rating = 5;
    	[players addObject:player];
    	player = [[Player alloc] init];
    	player.name = @"Dave Brubeck";
    	player.game = @"Texas Hold’em Poker";
    	player.rating = 2;
    	[players addObject:player];
    	UITabBarController *tabBarController = 
         (UITabBarController *)self.window.rootViewController;
    	UINavigationController *navigationController = 
         [[tabBarController viewControllers] objectAtIndex:0];
    	PlayersViewController *playersViewController = 
         [[navigationController viewControllers] objectAtIndex:0];
    	playersViewController.players = players;
        return YES;
    }




    edit: o yea and i used this tutorial for my coding before


    http://blog.webscale.co.in/?p=284


    it just seemed a lot simpler than the other one, i don't really like going into app delegate, it always give me errors when i mess with anything in there.

    but it seems like ray's tutorial is a much more better method of writing it.
     

Share This Page