2015-12-28 26 views
2

我在Storyboard的視圖控制器中設計了一個原型單元格,但不幸的是單元格中的UISlider未滑動。UISlider不能在原型單元格中滑動

注意: - Autolay爲此故事板啓用。

設計: -

enter image description here

這裏是代碼: -渲染單元在UITableview

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

    UITableViewCell *cell; 
    if(indexPath.row!=self.arrSelectRecipientsImages.count-1) 
    { 

     cell = [tableView dequeueReusableCellWithIdentifier:@"selectReciptenceTabCell" forIndexPath:indexPath]; 

    } 
    else 
    { 
     cell = [tableView dequeueReusableCellWithIdentifier:@"selectNearbyTabCell" forIndexPath:indexPath]; 
     UISlider *sliderNearby = (UISlider *)[cell.contentView viewWithTag:199]; 
     lblDistance = (UILabel *)[cell.contentView viewWithTag:190]; 
     sliderNearby.userInteractionEnabled = YES; 
     [sliderNearby setThumbImage:[UIImage imageNamed:@"NearbyCircle"] forState:UIControlStateNormal]; 
     [sliderNearby addTarget:self action:@selector(sliderNearbyAction:) forControlEvents:UIControlEventValueChanged]; 
    } 
return cell; 
} 
+0

我認爲'didSelectRow' touch委託與滑塊觸摸衝突。 –

+0

滑塊應該在表格視圖中工作,請詳細描述問題。 –

+0

問題非常簡單,滑動滑塊時不會滑動。@ A-Live – Vizllx

回答

1

的代碼工作正常,我認爲。 也無需設置用戶交互。

下面是示例代碼,您可以從中獲得幫助。它與自動佈局工作正常。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath]; 

    UILabel *lblTitle = (UILabel *)[cell viewWithTag:100]; 
    lblTitle.text = @"Hi"; 

    UISlider *slider = (UISlider *)[cell viewWithTag:101]; 
    slider.value = 0.2; 
    slider.tag = indexPath.row; 
    [slider addTarget:self action:@selector(sliderNearbyAction:) forControlEvents:UIControlEventValueChanged]; 
    return cell; 
} 

- (void)sliderNearbyAction:(UISlider *)sender{ 
    NSLog(@"Slider %ld Value : %.2f",(long)sender.tag, sender.value); 
} 

輸出,日誌:

enter image description here

自動佈局截圖:

enter image description here

+0

謝謝!但可以發佈UISlider中使用的自動佈局的屏幕截圖。 – Vizllx

+0

@Vizllx當然。更新。 –

+0

嘿,阿希什,不,它沒有奏效! – Vizllx

0

嗯,是很無聊的,我還沒有提供這個問題的高度不同的細胞t指數路徑。這就是爲什麼最後一個單元格,即滑塊單元格顯示,但它的高度爲30,所以該區域外的任何輕擊或手勢都沒有響應。

+0

偉大的工作@Vizllx –

相關問題