小编Awa*_*ain的帖子

在视图生命周期中,UITableViewCell是否创建了其outlet/labels/subviews?

我正在尝试创建UIView一个子类的子视图UITableViewCell.基本上我想要一个与单元格大小相同的视图,并且位于单元格contentView和单元格之间backgroundView.

我想在引擎盖下的某个地方(可能在layoutSubviews),有一条线,UITableViewCell.m如:

if (self.contentView != nil) {
    [self addSubview:self.contentView];
}
Run Code Online (Sandbox Code Playgroud)

如果我想模仿Apple的方式,我应该把这些代码放在我自己的自定义UITableViewCell子类中?

此外,在我第一次尝试实现时,会显示子视图,但它的默认单元格高度为44px,而不是我指定的高度tableView:heightForRowAtIndexPath:.还有其他小错误出现,这就是为什么我想尝试复制Apple的实现,而不是尝试我自己的半功能.

编辑:这是我的代码到目前为止:

CustomTableViewCell.h

interface CustomTableViewCell : UITableViewCell
    @property (nonatomic, strong) UIView *newSubview;
@end
Run Code Online (Sandbox Code Playgroud)

CustomTableViewCell.m

- (void)layoutSubviews {
    [super layoutSubviews];

    if (self.newSubview != nil) {
        self.newSubview.autoresizingMask = UIViewAutoresizingFlexibleHeight;
        [self insertSubview:self.newSubview aboveSubview:self.backgroundView];
    }
}
Run Code Online (Sandbox Code Playgroud)

tableViewController.m

static NSString *CellIdentifier = @"Cell";
myCustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    cell = …
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview uiview ios

4
推荐指数
1
解决办法
1万
查看次数

UIGestureRecognizer未触发的可能原因?

我有一个子类UIView,让我们称之为TileView.m/h.

TileView.m,我有以下代码:( [setup]肯定被调用,我检查断点).

- (void)setup {
    self.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(testPressed:)];
    [self addGestureRecognizer:tap];
}

- (void)testPressed:(UITapGestureRecognizer *)sender {
    NSLog(@"tap pressed");
}
Run Code Online (Sandbox Code Playgroud)

出于某种原因,testPressed当我点击视图时,不会调用该方法!

奇怪的是,如果我将TileView类复制到一个空白的xCode项目并在那里设置它,一切都很好.这是特殊的,因为手势首先由子视图处理,然后由超级视图处理 - 因此tile类不应受其超级视图的影响.此外,手势完全包含在TileView课程中.

作为参考,tile视图嵌套在: Controller -> controller's view -> scroll view -> container view -> tile viewpattern中.

我试过没有成功:

  • 在TileView及其所有子视图上设置userInteractionEnabled = YES.
  • 从代码的其他部分删除所有手势识别器以避免干扰.
  • 设置tap.delegate = self然后gestureRecognizer:shouldRecognizeSimultaneously...始终实施return YES;

没运气 :/

还有什么想法可能会出错?或者我可以运行哪些测试来更详细地了解问题?

编辑:更多细节

回想一下,tile视图嵌套在: Controller -> controller's …

iphone uiscrollview uigesturerecognizer ios

1
推荐指数
1
解决办法
2507
查看次数