2015-02-05 1 views
0

동적 프로토 타입 셀이있는 tableviewcontroller를 만들었습니다. 이보기 내에서 사용자는 버튼 누르기로 위치 리뷰를 입력 할 수 있으며 UI 슬라이더로 위치를 1에서 10까지 평가할 수 있습니다. 리뷰는 tableviewcontroller 내에서 UIAlertController로 수행되지만 UISlider는 셀 자체 내에 있습니다. 두 tableviewcontroller 내의 핵심 데이터를 저장하려고합니다. 그러나 UISlider 등급 값은 tableviewcontroller에서 사용할 수 없습니다. 셀에서 tableview로 참조하는 방법이 있습니까? 아니면 두 개의 별도 저장 함수가 있어야합니까? 여기까지는 내 코드 중 일부가 있습니다 - Tableview 컨트롤러 내에서 프로토 타입 셀의 UISLider 값에 할당 된 변수를 인식하지 못합니다. 어떤 도움을 주셔서 미리 감사드립니다! 내 tableviewcell에서CoreData를 UITableViewController에 저장하지만 UISlider 데이터는 Prototype 셀에만 있습니다. CoreData에 저장하려면 어떻게해야합니까?

: 저장 내 tableviewcontroller에서

class WineryInfoTableViewCell: UITableViewCell { 

@IBOutlet weak var ratingLabel: UILabel! 
@IBOutlet weak var sliderbutton: UISlider! 

@IBAction func sliderValueChanged(sender: UISlider) { 
    var ratingValue = Float(sender.value) 
    var roundedRatingValue = roundf(ratingValue/0.5)*0.5 
    ratingLabel.text = "\(roundedRatingValue)" 

} 

@IBAction의 FUNC() {

if let managedObjectContext = (UIApplication.sharedApplication().delegate as AppDelegate).managedObjectContext { 

     myRatingData = NSEntityDescription.insertNewObjectForEntityForName("WineryReview", inManagedObjectContext: managedObjectContext) as wineryReview 

     myRatingData.wineryName = wineryNames 
     //myRatingData.rating = ratingLabel.text how do I call this for saving? 
     myRatingData.review = myRatingEntry 


     var e:NSError? 
     if managedObjectContext.save(&e) != true { 
      println("insert error: \(e!.localizedDescription)") 
      return 
     } 
    } 

    // If all fields are correctly filled in, extract the field value 
    println("Winery: " + myRatingData.wineryName) 
    println("Review: " + myRatingData.review) 
    //println("Rating: " + ratingLabel.text!) how do I call this for saving? 

} 

답변

0

나는 스위프트 여전히 새로운 해요,하지만 난 나는 당신의 딜레마의 일부에 대한 해답을 가지고 있다고 생각합니다. 테이블 셀에서 UISlider를 참조하려면 '태그'를 사용하여 참조를 가져올 수 있습니다. 예를 들어

:

let cell = tableView.dequeueReusableCellWithIdentifier(TableViewCellIdentifiers.someCell, forIndexPath: indexPath) as UITableViewCell

위의 예에서 let slider = cell.viewWithTag(100) as UISlider

, 나는 100의 태그로 UISlider를 할당 사용했을 것이다, 그래서 사용하여에 대한 참조를 얻을 수 있어요 cell.viewWithTag (100).

이것이 작동하지 않으면 나를 용서하십시오!

0

WineryReview 개체를 셀에 전달하고 해당 등급을 sliderValueChanged에서 직접 설정할 수 있습니다. cellForRowAtIndex에서

:

cell.wineryReview = myReviewData 

TableViewCell에서 :

@IBOutlet weak var ratingLabel: UILabel! 
@IBOutlet weak var sliderbutton: UISlider! 

var wineryReview: WineryReview? 

@IBAction func sliderValueChanged(sender: UISlider) { 
    var ratingValue = Float(sender.value) 
    var roundedRatingValue = roundf(ratingValue/0.5)*0.5 

    wineryReview.rating = roundedRatingValue 

    ratingLabel.text = "\(roundedRatingValue)" 
} 

당신은 당신이 좋아하는 경우 TableViewController에서 문맥에 저장 호출 할 수 있습니다. 나는 프로젝트에서 이와 비슷한 것을했다.