2015-12-16 11 views
0

我正在嘗試使用parentchildaccordion cells創建單個tableview。對於這個手風琴單元格,我創建了兩個單元格到單個單元格tableview storyboard中,並給出了單獨的Identifier和兩個單元格的類,並在下面的方法中執行了一些邏輯。現在的問題是我需要訪問自定義單元類,並且我已經將outlets單元格storyboard UI連接到自定義類,但是我不能在以下方法中訪問該UI。如何使用目標C訪問自定義類到主類中?

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 

     //cell = [[[NSBundle mainBundle] loadNibNamed:@"CCell" owner:self options:nil] objectAtIndex:1]; 
     cell = [tableView dequeueReusableCellWithIdentifier:@"parentCell"]; 

    } 
    NSDictionary *dicForIndex = [self.arForTable objectAtIndex:indexPath.row]; 


    if ([[dicForIndex valueForKey:@"isChild"] boolValue] == YES) { 

     //cell = [[[NSBundle mainBundle] loadNibNamed:@"CCell" owner:self options:nil] objectAtIndex:0]; 
     cell = [tableView dequeueReusableCellWithIdentifier:@"childCell"]; 

     UILabel *labelName = (UILabel*)[cell viewWithTag:1001]; 
     labelName.text = [dicForIndex valueForKey:@"name"]; 

    }else{ 

     UILabel *labelName = (UILabel*)[cell viewWithTag:1001]; 
     labelName.text = [dicForIndex valueForKey:@"name"]; 

    } 
    [cell setIndentationLevel:[[[self.arForTable objectAtIndex:indexPath.row] valueForKey:@"level"] intValue]]; 
    return cell; 
} 
+0

那你要訪問? 「細胞」?什麼是「細胞」的類名? – anhtu

+0

實際上,我已經創建了兩個單元格到tableview storyboard中,上面提到的兩個自定義類我使用的代碼,但是plm我不能訪問上面的方法@ anthu –

+0

「兩個自定義類」中的自定義類出口UI。它是什麼名字? – anhtu

回答

1

你可以這樣做:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 
     cell = [tableView dequeueReusableCellWithIdentifier:@"parentCell"]; 
     parenttableviewCell *cellParent = (parenttableviewCell *)cell; 
     // custom something ... 
     cellParent.labelA.text = @"A"; 
    } 
    ... 
    if ... 
    { 
     cell = [tableView dequeueReusableCellWithIdentifier:@"childCell"]; 
     childtableviewCell *cellchild = (childtableviewCell *)cell; 
     // custom something ... 
    } 

return cell; 
+0

哇大哥們!謝謝!@anthu –

相關問題