BBS > objective c

CommonCell

작성자 : 이창우 (x1wins) | 등록일 : 2013-12-02 | 목록
첨부 파일이 없습니다.
첨부 이미지가 없습니다.
#import <UIKit/UIKit.h>

@interface CommonCell : UITableViewCell

+ (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
+ (CGFloat) height;
+ (CGFloat)textSizeWithLabel:(UILabel*)label;

@end
#import "CommonCell.h"

@implementation CommonCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

+ (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class)];
    
    if( cell == nil )
    {
//        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self.class)];
        NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self.class)
                                                      owner:self options:nil];
        cell = [nibs objectAtIndex:0];
    }
    
    cell.textLabel.numberOfLines = 0;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
}

+ (CGFloat)textSizeWithLabel:(UILabel*)label
{
    CGSize strengthHomeContentTextSize = [label.text sizeWithFont:label.font
                                                constrainedToSize:CGSizeMake(label.frame.size.width, 10000)
                                                    lineBreakMode:label.lineBreakMode];
    
    return strengthHomeContentTextSize.height;
}

+ (CGFloat) height
{
    NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self.class)
                                                  owner:self options:nil];
    
    UITableViewCell *cell = [nibs objectAtIndex:0];
    return cell.frame.size.height;
}

@end
+ (CGFloat) heightWithPreviewDataObject:(EUROPreviewDataObject*)previewDataObject
{
    
    
    NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self.class)
                                                  owner:self options:nil];
    LeagueAnalysisDetailStrengthWeaknessCell *cell = [nibs objectAtIndex:0];
    
    [cell setPreviewDataObject:previewDataObject];
    [cell setFontWithLabel:cell.strengthHomeContent];
    [cell setFontWithLabel:cell.strengthAwayContent];
    [cell setFontWithLabel:cell.weakHomeContent];
    [cell setFontWithLabel:cell.weakAwayContent];
    
    int height = cell.frame.size.height;

    height -= cell.strengthHomeContent.frame.size.height;
    height += [LeagueAnalysisDetailStrengthWeaknessCell textSizeWithLabel:cell.strengthAwayContent];
    
    height -= cell.weakHomeContent.frame.size.height;
    height += [LeagueAnalysisDetailStrengthWeaknessCell textSizeWithLabel:cell.strengthAwayContent];
    
    height -= cell.strengthAwayContent.frame.size.height;
    height += [LeagueAnalysisDetailStrengthWeaknessCell textSizeWithLabel:cell.weakHomeContent];
    
    height -= cell.weakAwayContent.frame.size.height;
    height += [LeagueAnalysisDetailStrengthWeaknessCell textSizeWithLabel:cell.weakAwayContent];
    
    if(height < cell.frame.size.height)
    {
        height = cell.frame.size.height;
    }

    return height;
}
~~
로그인 하셔야 댓글을 사용하실수 있습니다.
댓글쓰기를 누르면 로그인 페이지로 이동 후 돌아옵니다.
총 댓글 겟수 1
이창우(x1wins) | 2013-12-03
http://stackoverflow.com/questions/18897896/replacement-for-deprecated-sizewithfont-in-ios-7
번호 제목 등록일 작성자 조회수
667 uinavigation 영역 문제 (0) 2014-04-10 이창우 1366
661 cocos2d-x start (0) 2014-02-27 이창우 2383
660 unsupported compiler (0) 2014-02-26 이창우 1395
656 UIView에서 viewDidUnload (0) 2014-01-05 이창우 1773
655 UItextView height (0) 2014-01-03 이창우 2286
654 UIView contentMode (0) 2013-12-15 이창우 1729
653 UILabel 줄간격, 사이즈 (0) 2013-12-10 이창우 4985
652 네비게이션에 세그먼트 달기 (0) 2013-12-09 이창우 1624
651 scrollview kvo sample (0) 2013-12-08 이창우 1426
650 UIImageView fade 효과 (0) 2013-12-04 이창우 1557
649 block 안에서 변수 선언 (0) 2013-12-04 이창우 1583
648 UIRefreshControl sample (0) 2013-12-03 이창우 1435
-> CommonCell (1) 2013-12-02 이창우 1173
646 NSDate 주차 뽑기 (0) 2013-12-02 이창우 875
643 CommonCell (0) 2013-12-01 이창우 674
642 NSDate <-> long (0) 2013-11-29 이창우 1020
641 nsdate plus 1 month (0) 2013-11-29 이창우 831
639 NSDate 예제 (0) 2013-11-28 이창우 991
638 NSException (0) 2013-11-28 이창우 939
637 XCode hex color 플로그인 (0) 2013-11-28 이창우 1338
< 1 2 3 4 5 6 7 8 9 10 >
글쓰기 검색