簡體   English   中英

在tableviewcell中以編程方式創建的視圖中的問題

[英]Issue in view created programmatically in tableviewcell

我正在實現一個包含TableViewUIViewController ,我試圖添加一個在TableViewCell中以編程方式創建的視圖,並在滾動視圖時將其隱藏並起作用。 任何人都可以幫助我

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
   if(cell==nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];

    }
    UIView *BottomView=[[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height , self.view.frame.size.width, 50)];
    BottomView.backgroundColor=[UIColor redColor];
   [cell addSubview:BottomView];
    return cell;
}

更改

[cell addSubview:BottomView];

[cell.contentView addSubview:BottomView];

兄弟改變您的BottomView框架,也許它會可見

    UIView *BottomView=[[UIView alloc] initWithFrame:CGRectMake(0, 10 , self.view.frame.size.width, 50)];
    BottomView.backgroundColor=[UIColor redColor];
   [cell addSubview:BottomView];

因為您將BottomView的高度設置為self.view.frame.size.height,這會使您的視圖超出單元格的框架,因此對其進行更改即可使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM