Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chhoda

macrumors 6502
Original poster
Oct 25, 2008
285
1
i am using a custom cell approach in UITableView. I am also trying to make the accessorystyle detaildisclosure. If i dont do custom cell, the detail mark shows up in right. if i do custom cell, detail mark does not show up in the right. has anybody noticed this ?

--CH
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Can you post the code for you custom cell? It's been a while since I did that but there are a few gotchas I remember, but kind of hard to tell what's going wrong without any code.
 

chhoda

macrumors 6502
Original poster
Oct 25, 2008
285
1
Code:
@interface MyCustomCell : UITableViewCell {
	//taking two buttons in every cell.
	UIImageView *img;
	UILabel *title;
	UILabel *subtitle;
}
@end


___________________________________________________________


@implementation MyCustomCell 

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 
	   forIndexPath:(NSIndexPath *)indexPath inViewController:(UIViewController *)vc {
	if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
		// [self setBackgroundColor:[UIColor clearColor]];
		
		NSString *strTitle = [mc.options objectAtIndex:indexPath.row];
		switch(indexPath.row) {
			case 0: img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"0.png"]];
				break;
			case 1: img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.png"]];
				break;
			case 2: img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"2.png"]];
				break;
			case 3: img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"3.png"]];
				break;
			case 4: img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"4.png"]];
				break;
			case 5: img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"5.png"]];
				break;
			case 6: img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"6.png"]];
				break;
			case 7: img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"7.png"]];
				break;
			case 8: img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"8.png"]];
				break;
			case 9: img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"9.png"]];
				break;
			case 10: img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"10.png"]];
				break;
			case 11: img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"11.png"]];
				break;
			case 12: img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"12.png"]];
				break;
		}
		title = [[UILabel alloc] init];
		UIFont *fontTitle = [UIFont fontWithName:@"Georgia" size:16.0];
		if(title) {
			[title setText:strTitle];
			[title setBackgroundColor:[UIColor clearColor]];
			title.font = fontTitle;
		}
//		else {
//			[self.textLabel setText:strTitle];
//			[self.textLabel setBackgroundColor:[UIColor clearColor]];
//			self.textLabel.font = fontTitle;
//		}
		
		subtitle=(1 == indexPath.row)?[[UILabel alloc] init]:nil;
		if(subtitle) {
			[subtitle setBackgroundColor:[UIColor clearColor]];
			subtitle.font=[UIFont fontWithName:@"Georgia" size:14.0];
		}
		[self addSubview:img];
		[self addSubview:title];
		if(subtitle)
			[self addSubview:subtitle];
		
//		[img release];
//		[title release];
//		[subtitle release];
	}
	return self;
}

#define celllayoutoffset 5
#define cellgroupoffset 10
- (void)layoutSubviews {
    /*
	// gradient
	CAGradientLayer *gradient = [CAGradientLayer layer];
	CGRect rct = self.bounds;
	gradient.cornerRadius = 5.0;
	gradient.frame = CGRectMake(rct.origin.x + celllayoutoffset, rct.origin.y, rct.size.width - (2 * celllayoutoffset), rct.size.height);
	gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor whiteColor] CGColor], (id)[[UIColor colorWithRed:0 green:0 blue:1 alpha:1.0] CGColor], nil];
	[self.layer insertSublayer:gradient atIndex:0];
	// gradient end
	*/
	CGRect rctCell = self.bounds;
	int ImgHeightAndWidth = rctCell.size.height - (2 * celllayoutoffset);
	
	CGRect rctImg = CGRectMake(cellgroupoffset + 3, celllayoutoffset, ImgHeightAndWidth, ImgHeightAndWidth);
	[img setFrame:rctImg];
	
	
	
	if(nil != subtitle) {
		CGRect rctTitle = CGRectMake((2 * cellgroupoffset) + rctImg.size.width, 0, rctCell.size.width - (2.5 * ImgHeightAndWidth), rctCell.size.height * 0.5);
		CGRect rctSubTitle = CGRectMake((2 * cellgroupoffset) + rctImg.size.width, ImgHeightAndWidth * 0.5, rctCell.size.width - (2.5 * ImgHeightAndWidth), rctCell.size.height * 0.5);
		[title setFrame:rctTitle];
		[subtitle setFrame:rctSubTitle];
		
		NSDate *now=[NSDate date];
		NSDateFormatter *tempdateformat=[[NSDateFormatter alloc] init];
		[tempdateformat setDateStyle:kCFDateFormatterLongStyle];
		NSString *dateformat=[tempdateformat stringFromDate:now];
		[subtitle setText:dateformat];
	}
	else {
		CGRect rctTitle = CGRectMake((2 * cellgroupoffset) + rctImg.size.width, 0, rctCell.size.width - (2.5 * ImgHeightAndWidth), rctCell.size.height);
		[title setFrame:rctTitle];
	}
}

- (void)dealloc {
	[super dealloc];
}

@end
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Instead of adding subviews directly to the cell, you should add them to its contentView. Try that and see if it helps.

Also your big switch can be greatly simplified to this:
Code:
img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.png", indexPath.row]]];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.