2016-02-15 26 views
1

我在主控制器的tableview具有包含3-4個按鈕的自定義單元格重疊視圖..見截圖enter image description here 當按鈕getpressed它填充一個小的tableview,當我選擇的行新的tableview它不是作品ai的預期看截圖enter image description here的UITableView與更新錯誤的索引路徑

現在的問題是新的tableview其設定選擇值爲oldtableview相同指數

這裏的代碼:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *MyIdentifier = @"FollowUp"; 
    UITableViewCell *cell ;//= [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] ; 
    if (tableView == tblScribedBy) { 
     [cell.textLabel setText:[arrScribedBy objectAtIndex:indexPath.row]]; 
     [cell.textLabel sizeToFit]; 
    } 
    if (tableView == tblDropDown) { 
     if ([btnCLicked isEqualToString:@"Cell"]) { 
      [cell.textLabel setText:[totalRows objectAtIndex:indexPath.row]]; 
      [cell.textLabel sizeToFit]; 
     } 
     else if ([btnCLicked isEqualToString:@"Drop"]){ 
      [cell.textLabel setText:[arrFUDrop objectAtIndex:indexPath.row]]; 
     } 
    } 
    if (tableView == tblView) { 
     FUCellView * cell = [tableView dequeueReusableCellWithIdentifier:@"myCell"]; 
     if (!cell) 
     { 
      [tblView registerNib:[UINib nibWithNibName:@"FUCellView" bundle:nil] forCellReuseIdentifier:@"myCell"]; 
      cell = [tblView dequeueReusableCellWithIdentifier:@"myCell"]; 
      } 
     [cell.btntfFUCell addTarget:self action:@selector(actionTfCellFU:) forControlEvents:UIControlEventTouchUpInside]; 
     [cell.btntfFUCell setTag:indexPath.row]; 
     [cell.btnDropFU addTarget:self action:@selector(actionDropFU:) forControlEvents:UIControlEventTouchUpInside]; 
     [cell.btnDropFU setTag:indexPath.row]; 

     return cell; 
    } 

    return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    FUCellView *cell = (FUCellView *)[tblView cellForRowAtIndexPath:indexPath]; 

    if (tableView == tblScribedBy) { 
     [self.btnScribedBy setTitle:[NSString stringWithFormat:@" %@",[arrScribedBy objectAtIndex:indexPath.row]] forState:UIControlStateNormal ]; 
     [tblScribedBy setHidden:TRUE]; 
    } 

    else if (tableView == tblDropDown) { 
     if ([btnCLicked isEqualToString:@"Cell"]) { 
      [cell.tfFUCell setText:[totalRows objectAtIndex:indexPath.row]]; 
     } 
     else if ([btnCLicked isEqualToString:@"Drop"]){ 
      [cell.btnDropFU setTitle:[arrFUDrop objectAtIndex:indexPath.row] forState:UIControlStateNormal]; 
     } 
     [tblDropDown setHidden:YES]; 
    } 

} 

//----- Action for Buttons 
-(void)actionTfCellFU:(UIButton *)sender 
{ 
    btnCLicked = @"Cell"; 
    [tblDropDown setHidden:FALSE]; 
    [tblDropDown reloadData]; 
} 
-(void)actionDropFU:(UIButton *)sender 
{ 
    btnCLicked = @"Drop"; 
    [tblDropDown setHidden:FALSE]; 
    [tblDropDown reloadData]; 

} 
+0

顯示呈現所述第二表視圖和視頻在@Wain這樣其附加 – Wain

+0

處理抽頭碼的代碼*細胞= [的tableView dequeueReusableCellWithIdentifier:@「了myCell」 forIndexPath:indexPath]; – iDeepak

+0

雙端隊列細胞兩個表 –

回答

0

FUCellView *cell = (FUCellView *)[tblView cellForRowAtIndexPath:indexPath];

這條線被用於獲取細胞更新,但它的使用在第二表視圖中選擇的索引路徑以獲得在所述第一表視圖靶細胞。因此你會得到一個索引錯誤,並更新錯誤的單元格。

actionDropFU:被調用時,您需要確定一種方法,將實例變量存儲爲所選單元格的索引路徑。這是表1中的索引路徑,是您稍後在設置第二個表中的選擇結果時用於更新的路徑。一般來說,你不應該直接更新單元格,你應該更新你的數據模型。

對此的最佳選擇是不僅將目標和選擇器添加到單元格上的按鈕。相反,對單元格進行子類化併爲其添加屬性,以便稍後在與它進行交互時訪問它們。單元格應該是按鈕點擊的目標,當點擊按鈕並傳遞配置的數據(索引路徑)時,它應該回調視圖控制器(作爲單元格委託或目標)。

+0

發帖之前問題我使用了像你上面提到的Typcasting,但沒有發生:( – iDeepak

+0

?我沒有提到類型轉換? – Wain

相關問題