2013-10-17 10 views
0

我想利用開源UITableViewCell子類SWTableViewClass,但我遇到了問題。我收到響應「細胞的重新定義與不同類型的* _strong VS的UITableView * _strong」這是我的代碼:設置SWTableViewCell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
    static NSString *CellIdentifier = @"FactorCell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 

    } 

    SWTableViewCell *cell = (SWTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 
     NSMutableArray *leftUtilityButtons = [NSMutableArray new]; 
     NSMutableArray *rightUtilityButtons = [NSMutableArray new]; 

     [leftUtilityButtons addUtilityButtonWithColor: 
     [UIColor colorWithRed:0.07 green:0.75f blue:0.16f alpha:1.0] 
               icon:[UIImage imageNamed:@"check.png"]]; 
     [leftUtilityButtons addUtilityButtonWithColor: 
     [UIColor colorWithRed:1.0f green:1.0f blue:0.35f alpha:1.0] 
               icon:[UIImage imageNamed:@"clock.png"]]; 
     [leftUtilityButtons addUtilityButtonWithColor: 
     [UIColor colorWithRed:1.0f green:0.231f blue:0.188f alpha:1.0] 
               icon:[UIImage imageNamed:@"cross.png"]]; 
     [leftUtilityButtons addUtilityButtonWithColor: 
     [UIColor colorWithRed:0.55f green:0.27f blue:0.07f alpha:1.0] 
               icon:[UIImage imageNamed:@"list.png"]]; 

     [rightUtilityButtons addUtilityButtonWithColor: 
     [UIColor colorWithRed:0.78f green:0.78f blue:0.8f alpha:1.0] 
               title:@"More"]; 
     [rightUtilityButtons addUtilityButtonWithColor: 
     [UIColor colorWithRed:1.0f green:0.231f blue:0.188 alpha:1.0f] 
               title:@"Delete"]; 

     cell = [[SWTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
             reuseIdentifier:CellIdentifier 
            containingTableView:tableView 
       // For row height and selection 
            leftUtilityButtons:leftUtilityButtons 
            rightUtilityButtons:rightUtilityButtons]; 
//  cell.delegate = self; 

} 

    DDFactor *factor = [_decision factor:indexPath.row]; 

    [[cell textLabel] setText:[factor title]]; 


    return cell; 

} 
+0

你在'UITableViewCell'中第二次聲明'cell',第二次在同一個方法中聲明'SWTableViewCell'。 – Amar

+0

在這裏,您嘗試從可重用單元隊列中獲取單元格兩次,這可能會導致您遇到該錯誤。 – Suryakant

回答

0

的問題是,你重新聲明一個變量cell兩次。你的代碼應該是這樣的:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
    static NSString *CellIdentifier = @"FactorCell"; 

    SWTableViewCell *cell = (SWTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 
     // making a guess here as to how to initialize SWTableViewCell 
     cell = [[SWTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 

    } 

    // .. 

}