Here the story, before, i use xcode 4 and using library ECSSlidingView Menu, it work nicely but after i clone it to new project using xcode 5, many thing messed up, even with no code change!
the view shifted up, and the imageview isn't displayed
both using this chunk of code (tell me if you need more)
For CellView @implementation SideMenuTableViewCell
@synthesize indexpath;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[self setAccessoryCheckmarkColor:[UIColor whiteColor]];
[self setDisclosureIndicatorColor:[UIColor whiteColor]];
[self setAccessoryCheckmarkColor:[UIColor whiteColor]];
// Disable this as this will overlaped with draw to stroke line
//UIView * backgroundView = [[UIView alloc] initWithFrame:self.bounds];
//[backgroundView setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
//[backgroundView setBackgroundColor:[CustomConfiguration CFG_THEME_COLOR_BLUE]];
//[self setBackgroundView:backgroundView];
//
[self setBackgroundColor:[CustomConfiguration CFG_THEME_COLOR_BLUE]];
[self setBackgroundColor:[UIColor clearColor]];
[self.textLabel setTextColor:[CustomConfiguration CFG_THEME_COLOR_YELLOW]];
[self.textLabel setFont:[CustomConfiguration CFG_THEME_FONT_LARGEBUTTON]];
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)setAccessoryType:(UITableViewCellAccessoryType)accessoryType{
[super setAccessoryType:accessoryType];
if(accessoryType == UITableViewCellAccessoryCheckmark){
MMCustomCheckmark * customCheckmark = [[MMCustomCheckmark alloc] initWithFrame:CGRectMake(0, 0, 15, 15)];
[customCheckmark setColor:self.accessoryCheckmarkColor];
[self setAccessoryView:customCheckmark];
}
else if(accessoryType == UITableViewCellAccessoryDisclosureIndicator){
MMDisclosureIndicator * di = [[MMDisclosureIndicator alloc] initWithFrame:CGRectMake(0, 0, 10, 14)];
[di setColor:self.disclosureIndicatorColor];
[self setAccessoryView:di];
}
else {
[self setAccessoryView:nil];
}
}
// Configure cell.imageView size and position
- (void)layoutSubviews {
[super layoutSubviews];
self.imageView.frame = CGRectMake(50, 50, 25, 25);
}
-(void)drawRect:(CGRect)rect{
if (self.indexpath.row > 0) {
return;
}
//// General Declarations
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = UIGraphicsGetCurrentContext();
//// Frames
CGRect frame = CGRectMake(0, -1, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds)+1);
UIColor *customWhite = [UIColor colorWithRed:251.0/255.0 green:251.0/255.0 blue:249.0/255.0 alpha:1];
//// Fill Drawing
CGRect fillRect = CGRectMake(CGRectGetMinX(frame), CGRectGetMinY(frame), CGRectGetWidth(frame), CGRectGetHeight(frame) - 1);
UIBezierPath* fillPath = [UIBezierPath bezierPathWithRect: fillRect];
CGContextSaveGState(context);
[fillPath addClip];
CGContextRestoreGState(context);
//// TopStroke Drawing
// Do not draw top stroke unless section index is greater than 0
if (self.indexpath.section > 0) {
UIBezierPath* topStrokePath = [UIBezierPath bezierPathWithRect: CGRectMake(CGRectGetMinX(frame), CGRectGetMinY(frame)+1, CGRectGetWidth(frame), 1)];
[customWhite setFill];
[topStrokePath fill];
}
//// Highlight Drawing
//// BottomStroke Drawing
if (self.indexpath.row == 0) {
UIBezierPath* bottomStrokePath = [UIBezierPath bezierPathWithRect: CGRectMake(CGRectGetMinX(frame), CGRectGetMinY(frame) + CGRectGetHeight(frame) - 1, CGRectGetWidth(frame), 1)];
[customWhite setFill];
[bottomStrokePath fill];
}
//// Cleanup
//CGGradientRelease(gradient2);
CGColorSpaceRelease(colorSpace);
}
@end
For TableView, method cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"MenuItemCell";
UITableViewCell *cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Always redraw tanle cell
//if (cell == nil) {
cell = [[SideMenuTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
[cell setSelectionStyle:UITableViewCellSelectionStyleBlue];
[(SideMenuTableViewCell *)cell setIndexpath:indexPath];
//}
cell.imageView.bounds = CGRectMake(0, 0, 10, 10);
switch (indexPath.section) {
case MMDrawerSectionAccountSection:
switch (indexPath.row) {
case 0: {
cell.imageView.image = Nil;
cell.textLabel.text = [tableView.dataSource tableView:tableView titleForHeaderInSection:indexPath.section];
break; }
case 1: {
[cell.textLabel setText:[NSString stringWithFormat:@"%@ %@", [self.profileData valueForKey:@"firstName"], [self.profileData valueForKey:@"lastName"]]];
cell.imageView.image = [UIImage imageNamed:@"user.png"];
UILazyImageView *lazyImage = [[UILazyImageView alloc] init];
[lazyImage loadImageWithURL:[self.profileData valueForKey:@"photoURL"]];
// Resize photo profile
CGRect resizeRect;
resizeRect.size = cell.imageView.image.size;
resizeRect.origin = CGPointMake(0.0, 0.0);
UIGraphicsBeginImageContext(resizeRect.size);
[lazyImage.image drawInRect:resizeRect];
UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
cell.imageView.image = resizedImage;
break; }
case 2: {
[cell.textLabel setText:LOC_EN_SIDEMENU_SAVEDARTICLE];
cell.imageView.image = [UIImage imageNamed:@"saved.png"];
break; }
case 3: {
[cell.textLabel setText:LOC_EN_SIDEMENU_SAVEDHOSPITAL];
cell.imageView.image = [UIImage imageNamed:@"savedhospital.png"];
break; }
case 4: {
[cell.textLabel setText:LOC_EN_SIDEMENU_LOGOUT];
cell.imageView.image = [UIImage imageNamed:@"logout.png"];
break; }
}
//[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
break;
case MMDrawerSectionMenuSection:{
switch (indexPath.row) {
case 0: {
cell.imageView.image = Nil;
cell.textLabel.text = [tableView.dataSource tableView:tableView titleForHeaderInSection:indexPath.section];
break; }
case 1: {
[cell.textLabel setText:LOC_EN_SIDEMENU_NEWSFEED];
[cell.imageView setImage:[UIImage imageNamed:@"newsfeed.png"]];
break; }
case 2: {
[cell.textLabel setText:LOC_EN_SIDEMENU_ARTICLE];
cell.imageView.image = [UIImage imageNamed:@"article.png"];
break; }
case 3: {
[cell.textLabel setText:LOC_EN_SIDEMENU_HOSPITAL];
cell.imageView.image = [UIImage imageNamed:@"pinmenu"];
break; }
case 4: {
[cell.textLabel setText:LOC_EN_SIDEMENU_PURCHASE];
cell.imageView.image = [UIImage imageNamed:@"purchase"];
break; }
}
//[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
break;
}
default:
break;
}
return cell;
}