2016-10-17 2 views
0

셀이있는 표가 있습니다. 셀 내에서 선택기보기가tableView 셀 스위프트에 데이터 전달

enter image description here

지금은 내가 피커보기

에서 데이터를 표시 할 수있는 테이블 뷰 셀에 부모 컨트롤러에서 데이터 (객체의 배열)을 전달하려는
var foodServings:[FoodUnit]=[] 
func tableView(tableView:UITableView, cellForRowAtIndexPath indexPath:NSIndexPath)->UITableViewCell{ 
    let cell = tableView.dequeueReusableCellWithIdentifier("recipeIngredientCell",forIndexPath: indexPath) as! ReceiptIngredientsViewCell 
    let row = indexPath.row 
    cell.ingredientName.text = foods[row].name 
    cell.ingredientText.text = foodQuantities[row] 

    // cell.foodServings = self.foodServings 

    return cell 

} 

데이터를 셀로 보낼 수 있지만이 작업이 필요하지 않았 으면합니다. 와

Thats how the table is constructed

:

내가 그것을 조금 clearify하려고

cell.ingredientName.text = foods[row].name 
cell.ingredientText.text = foodQuantities[row] 

나는 텍스트 뷰에서 예를 들어 콩에 대한 셀 라벨과 텍스트에 액세스 할 수 있습니다를

그러나 피커 뷰를 채울 수 있도록 각 셀에 데이터 배열을 보내야 피커 뷰를 채울 수 있습니다.

+0

실제로 할 수 있고 사용한 방식이 정확합니다. 무엇이 문제입니다? –

+0

이 경우, 예, 그렇다면 어떻게 데이터를 테이블 뷰 셀로 전달할 수 있습니까? –

답변

0

이 확인하십시오 : "recipeIngredientCell"식별자 셀이 스토리 보드에이

  • 이된다?
  • foods 배열은 데이터로 채워 집니까?
  • foodQuantities 배열이 데이터로 채워 집니까?
  • tableView (_ : numberOfRowsInSection :) 메소드를 구현 했습니까? 이 방법은 약 UIPickerView

    당신이 당신의 ViewController에 UIPickerViewDelegateUIPickerViewDataSource를 연결나요 모든 foods.count

+0

예 모두 검사 된 객체 배열을 셀에 전달하면 피커 뷰를 채울 수 있습니다 –

0

첫째, 당신은 this 튜토리얼을 확인할 수 있습니다 예를 들어, 행의 수를 반환해야합니까? 그 후

, 당신이 그 대리자 메서드를 구현해야합니다 :

// The number of rows of data 
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { 
    return foodServings.count 
} 

// The data to return for the row and component (column) that's being passed in 
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { 
    return foodServings[row] 
} 

// Catpure the picker view selection 
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { 
    // This method is triggered whenever the user makes a change to the picker selection. 
    // You can update your cell's UI here. For example: 
    let indexpath = NSIndexPath(row: , section:) 
    let cell = self.tableView(tableView, cellForRowAt: indexPath)  
    cell.yourTextField.text = foodServings[row] 
} 

당신이 우리를 제공하는 것을, 난 단지 당신의 foodServings 배열이 비어 있음을 알 수 있습니다, 그래서 당신은 나에게 모든 코드를 제시해주십시오 수에서 이 수업에서?

+0

아마도 약간 부정확했습니다. 피커보기가 작동하지만 viewController 개체를 가진 배열을 나중에 picker보기를 채우는 데 사용할 수있는 셀 컨트롤러로 전달해야합니다. –

+0

@chrissychristancuvic 그러면 충분히 정확하고 질문을 수정하고 코드를 추가하고, 한 블록의 코드를 넣고 사람들이 의도를 추측하도록하는 대신 현재 가지고있는 것을 설명하고, 무엇을하고 싶은지, 문제는 무엇인지를 설명하십시오. –

1

데이터를 전달하는 경우 값을 셀에 전달하기 위해 전역 변수/생성자를 사용할 수 있습니다.