自定义UITableViewCell - 现在UITableView不滚动

时间:2013-04-08 04:48:56

标签: objective-c uitableview

创建一个空的xib。 创建了一个覆盖UITableViewCell(UserCell)的类。

添加一个自定义逻辑片段,只需格式化一些字符串进行显示,并将IB中的两个标签连接起来。

我的视图控制器拥有UITableView。我已将视图控制器设置为数据源。 以下是我用自定义单元格填充它的方法。

(做了:http://www.highoncoding.com/Videos/823_Creating_a_Custom_UITableViewCell.aspx

-(UserCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UserCell* cell = [tableView dequeueReusableCellWithIdentifier:@"Users Table"];

    if (!cell) {
        NSArray* topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"UserCell" owner:nil options:nil];
        for (id currentObject in topLevelObjects) {
            if ([currentObject isKindOfClass:[UserCell class]]) {
                cell = (UserCell*) currentObject;
                break;
            }
        }
    }

    [cell setUserNameText:[[[_userDataManager getUsers] objectAtIndex:indexPath.row] name ]];
    [cell setNumberLabelText:indexPath.row];
    return cell;
}

出于某种原因,我无法滚动。在viewDidLoad:我正在我的桌面视图上打印scrollEnabled。它是“1”。

在我尝试添加自定义UITableViewCell之前,没有遇到过这种麻烦。 :(

非常感谢您的建议! :d

编辑:自定义单元代码。

#import "UserCell.h"

@implementation UserCell

@synthesize textLabel, numberLabel;

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

-(void) setNumberLabelText:(NSInteger)text {
    self.numberLabel.text = [[NSString alloc] initWithFormat:@"# %d", text];
}

-(void) setUserNameText:(NSString*)text {
    self.userNameLabel.text = text;
}

@end

1 个答案:

答案 0 :(得分:0)

回答这个问题(我有时候是derp)

我没有使用触控板做过多iOS操作。好像我期待两个手指滚动在模拟器上“滚动”。它没有!

为其他任何有这个问题的人提醒。