【问题标题】:How to subclass SWTableViewCell library programmatically? (Swipe cells)如何以编程方式子类化 SWTableViewCell 库? (滑动单元格)
【发布时间】:2013-12-01 20:53:37
【问题描述】:

我想用SWTableViewCell Library 实现一个 SwipeCell。我想创建一个SWTableViewCell 的子类以更轻松地对其进行自定义。我已经做到了,但它不起作用。我想我忘记了一些东西,我的意思是,刷卡不起作用,但我可以看到单元格。

这是我的子类代码:

.h

#import <UIKit/UIKit.h>
#import "SWTableViewCell.h"

@interface WPUserPlanCell : SWTableViewCell
@property (strong, nonatomic)WPCustomLabel *tileLabel;
@property (strong, nonatomic)WPCustomLabel *dateLabel;
@property (nonatomic) id <SWTableViewCellDelegate> delegate;

-(void)configureCellWithTitle:(NSString *)title andDate:(NSString *)date;

@end

.m

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{    
    UITableView * table= nil;
    WPUserPlanCell *cell = (WPUserPlanCell *)self;
    if([cell isKindOfClass:[UITableViewCell class]]){
        table = (UITableView *)cell.superview;
        if(IS_OS_7_OR_LATER){
            table = (UITableView *)cell.superview.superview;
        }
    }
    NSMutableArray *rightUtilityButtons = [NSMutableArray new];

    [rightUtilityButtons sw_addUtilityButtonWithColor:
     [UIColor colorWithRed:1.0f green:0.231f blue:0.188 alpha:1.0f] title:@"Delete"];

     self = [super initWithStyle:style
                                  reuseIdentifier:reuseIdentifier
                              containingTableView:table
                               leftUtilityButtons:nil
                              rightUtilityButtons:rightUtilityButtons];

    if (self) 
    {
        CGRect labelFrame = UIEdgeInsetsInsetRect(self.bounds, titleLabelInsets);
        labelFrame.size = kLabelSize;

        tileLabel = [[WPCustomLabel alloc] initWithFrame:labelFrame];
        [tileLabel setTextColor:[UIColor blackColor]];
        [tileLabel setFont:[UIFont systemFontOfSize:14]];
        [tileLabel setBackgroundColor:[UIColor clearColor]];
        tileLabel.textAlignment = NSTextAlignmentLeft;
        [self addSubview:tileLabel];

        labelFrame.size.width = self.bounds.size.width - kLabelSize.width;
        labelFrame.origin.x = CGRectGetMaxX(labelFrame) + 15;

        dateLabel = [[WPCustomLabel alloc] initWithFrame:labelFrame];
        [dateLabel setTextColor:[UIColor orangeColor]];
        [dateLabel setFont:[UIFont systemFontOfSize:14]];
        [dateLabel setBackgroundColor:[UIColor clearColor]];
        dateLabel.textAlignment = NSTextAlignmentRight;
        [self addSubview:dateLabel];
    }
    return self;
}

- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    if (aTableView == self.tableView) {

        Plan *plan = (Plan *)[self.fetchedResultsController objectAtIndexPath:indexPath];

        // Creating Reusable Cell
        WPUserPlanCell *cell = (WPUserPlanCell *)[aTableView dequeueReusableCellWithIdentifier:PlanCellIdentifier];
        if (cell == nil)
        {
            // INIT REUSABLE CELL
            cell = [[WPUserPlanCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:PlanCellIdentifier] ;
            cell.delegate = self;
        }

        [cell configureCellWithTitle:plan.name andDate:plan.date];
        return cell;
    }
    return nil;
}

【问题讨论】:

    标签: ios iphone objective-c uitableview


    【解决方案1】:

    你可以试试

    [cell setCellHeight:_customHeight]; 
    

    如果您的单元格高度不是默认值。

    【讨论】:

      猜你喜欢
      • 2010-11-22
      • 2011-11-22
      • 1970-01-01
      • 2015-01-15
      • 2020-05-31
      • 1970-01-01
      • 2021-09-02
      • 2011-10-04
      • 1970-01-01
      相关资源
      最近更新 更多