PDA

View Full Version : Can Someone Look At My Code?




loon3y
Feb 29, 2012, 06:52 PM
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???







- (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;
}



isthisonetaken
Feb 29, 2012, 07:04 PM
Are you using ARC? If so, it won't like the autorelease at the end. Try removing that and see if it starts working!

ArtOfWarfare
Feb 29, 2012, 07:12 PM
A description of how this isn't working might also be helpful.

loon3y
Feb 29, 2012, 07:22 PM
Are you using ARC? If so, it won't like the autorelease at the end. Try removing that and see if it starts working!

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

----------

A description of how this isn't working might also be helpful.




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.

isthisonetaken
Feb 29, 2012, 07:28 PM
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.

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.

loon3y
Feb 29, 2012, 07:32 PM
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.



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.





#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

ArtOfWarfare
Feb 29, 2012, 07:41 PM
Since you're already using storyboards, you may as well set up your custom cells in the way described in this tutorial:

http://www.raywenderlich.com/5191/beginning-storyboards-in-ios-5-part-2

loon3y
Feb 29, 2012, 07:49 PM
Since you're already using storyboards, you may as well set up your custom cells in the way described in this tutorial:

http://www.raywenderlich.com/5191/beginning-storyboards-in-ios-5-part-2



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.









- (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.