2017-04-26 94 views
1

*有很多相同的問題可用,我已經看到幾乎所有解決此問題,但無法得到正確的答案。 我必須在UITableView中添加一些自定義tableview單元格,所以我已經創建了自定義單元格並將其註冊到viewDidLoad函數中。自定義UITableViewCell不可見,我的第一個自定義單元格是可見的其他不是

typedef enum { 
    rProduct, 
    rAddMoreItem, 
    rItem, 
    rBill, 
    rApplyCoupon, 
    rGrandTotal, 
    rBottomInfo, 
    rNumerOfRows 
} SectionType; 

    [myTableView registerNib:[UINib nibWithNibName:[FPMCartTableViewCell tableViewIdentifier] bundle:nil] 
      forCellReuseIdentifier:[FPMCartTableViewCell tableViewIdentifier]]; 

    [myTableView registerNib:[UINib nibWithNibName:[FPMAddMoreItemsTableViewCell tableViewIdentifier] bundle:nil] 
      forCellReuseIdentifier:[FPMAddMoreItemsTableViewCell tableViewIdentifier]]; 

    [myTableView registerNib:[UINib nibWithNibName:[FPMItemTableViewCell tableViewIdentifier] bundle:nil] 
      forCellReuseIdentifier:[FPMItemTableViewCell tableViewIdentifier]]; 

    [myTableView registerNib:[UINib nibWithNibName:[FPMApplyCouponTableViewCell tableViewIdentifier] bundle:nil] 
      forCellReuseIdentifier:[FPMApplyCouponTableViewCell tableViewIdentifier]]; 


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

    int noOfRows = 0; 
    switch (section) { 
     case rProduct: 
      noOfRows = 2; 
     break; 
     case rAddMoreItem: 
      noOfRows = 1; 
      break; 
     case rItem: 
      noOfRows = 3; 
      break; 
     case rBill: 
      noOfRows = 1; 
      break; 
     case rApplyCoupon: 
      noOfRows = 1; 
      break; 
     case rGrandTotal: 
      noOfRows = 1; 
      break; 
     case rBottomInfo: 
      noOfRows = 1; 
      break; 
    } 
    return noOfRows; 
} 
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return rNumerOfRows; 
} 
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return 100; 
} 
And added in the cellForRowAtIndexPath method : 
    { 

    UITableViewCell *cell; 
     switch (indexPath.section) { 
      case rProduct: 
      { 
       NSString *identifer = [FPMCartTableViewCell tableViewIdentifier]; 
       FPMCartTableViewCell *cell1 = (FPMCartTableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifer]; 
       if (!cell1) 
       { 
        cell1 = [[FPMCartTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer]; 
       } 
       [self configureCell:cell1 forIndexPath:indexPath]; 
       cell = cell1; 
      } 
       break; 
      case rAddMoreItem: 
      { 
       NSString *identifer = [FPMAddMoreItemsTableViewCell tableViewIdentifier]; 
       FPMAddMoreItemsTableViewCell *cell2 = (FPMAddMoreItemsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifer]; 
       if (!cell2) 
       { 
        cell2 = [[FPMAddMoreItemsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer]; 
       } 
       cell2.backgroundColor = [UIColor redColor]; 
       cell = cell2; 
      } 
       break; 
      case rItem: 
      { 
       NSString *identifer = [FPMItemTableViewCell tableViewIdentifier]; 
       FPMItemTableViewCell *cell1 = (FPMItemTableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifer]; 
       if (!cell1) 
       { 
        cell1 = [[FPMItemTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer]; 
       } 
       cell = cell1; 
      } 
       break; 
      case rBill: 
      { 
       NSString *identifer = [FPMItemTableViewCell tableViewIdentifier]; 
       FPMItemTableViewCell *cell1 = (FPMItemTableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifer]; 
       if (!cell1) 
       { 
        cell1 = [[FPMItemTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer]; 
       } 
       cell = cell1; 

      } 
       break; 
      case rApplyCoupon: 
      { 
       NSString *identifer = [FPMApplyCouponTableViewCell tableViewIdentifier]; 
       FPMApplyCouponTableViewCell *cell1 = (FPMApplyCouponTableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifer]; 
       if (!cell1) 
       { 
        cell1 = [[FPMApplyCouponTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer]; 
       } 
       cell = cell1; 
      } 
       break; 
      case rGrandTotal: 
      { 
       NSString *identifer = [FPMItemTableViewCell tableViewIdentifier]; 
       FPMItemTableViewCell *cell1 = (FPMItemTableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifer]; 
       if (!cell1) 
       { 
        cell1 = [[FPMItemTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer]; 
       } 
       cell = cell1; 
      } 
       break; 
      case rBottomInfo: 
      { 
       if(!cell){ 
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"]; 
       } 
       cell.textLabel.text = @"Select Delivery and payment options in next step"; 
      } 
       break; 
     } 
    [cell setHidden:NO]; 
    return cell; 
    } 

但只有第一個單元是可見的,最後一個單元格哪一個是簡單的一個不othetrs。 enter image description here

我試圖登錄,但它涉及hidded =真默認

(lldb) po cell 
<FPMApplyCouponTableViewCell: 0x7f97ec067e00; baseClass = UITableViewCell; frame = (0 402; 375 100); hidden = YES; autoresize = W; layer = <CALayer: 0x600000238be0>> 
+0

你爲'numberOfSectionsInTableView'返回的實際值是多少?調用'numberOfRowsInSection'多少次? –

+0

@PhillipMills numberOfSectionsInTableView返回rNumerOfRows這是一個枚舉和numberOfRowsInSection調用7次 –

+0

您是否嘗試返回實際的整數值爲numberOfSectionsInTableView而不是枚舉? –

回答

1

其工作我現在只是做了每個細胞的alloc線的微小變化。

  if (!cell1) 
      { 
       cell1 = [[FPMCartTableViewCell alloc] init]; 
      } 

及其工作感謝您的努力。

相關問題