Swift 프로젝트와 관련하여 질문이 있습니다. TableViewController
에 여러 개의 셀이 있고 그 중 하나를 클릭하면 데이터가 tableViewController
에서 전달되는 ViewController
으로 이동합니다.viewcontroller에서 테이블 뷰의 다음 셀로 이동
ViewController
에있는 단추를 구현하면 ViewController
을 테이블보기 컨트롤러의 "다음 셀"의 내용으로 표시 할 수 있습니다. 예를 들어, 테이블 뷰 컨트롤러의 두 번째 셀을 클릭 했으므로 해당 셀에 해당하는 데이터를 표시하는 ViewController
으로 이동 한 다음 해당 "다음"버튼을 클릭하면 내용이 표시됩니다. viewController
테이블 뷰 컨트롤러의 세 번째 셀 어떻게하면 깨끗하게 처리 할 수 있습니까? 여기
tableViewController
에서
ViewController
에 데이터를 전달하는 데 사용하는 코드입니다 :
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if let a = articles {
return a.count
}
return 0
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) ->UITableViewCell{
let cell = tableView.dequeueReusableCellWithIdentifier("ArticleCell", forIndexPath: indexPath)
let article = articles?[indexPath.row]
if let a = article {
cell.textLabel?.text = a.articleName
cell.textLabel?.font = UIFont(name: "Avenir", size: 18)
cell.textLabel?.numberOfLines = 0
if let i = a.tableViewImage {
cell.imageView?.image = UIImage(named: i)
}
}
return cell
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "ShowArticle" {
let articleVC = segue.destinationViewController as? ArticleViewController
guard let cell = sender as? UITableViewCell,
let indexPath = tableView.indexPathForCell(cell) else {
return
}
articleVC?.article = articles?[indexPath.row]
}
}
을 viewController
에서 오른쪽 기사를 보여, 나는 viewDidLoad()
(내 viewController
이 쓴의 웹보기를 보여줍니다
if let a = article {
articleWebView.loadRequest(NSURLRequest(URL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource(a.articleLink, ofType: "html")!)))
}
나는 nextButton
에 연결된 한 : 기사, 나는 articleLink
에서 오는 클래스 Article
)가3210 :
@IBOutlet weak var nextButton: UIButton!
나는 스위프트에 비교적 새로운 해요, 그리고 내가 tableViewController
에 내 데이터를 선언하기 때문에 그것을하는 방법을 모르고는 (내 큰 문제가 없다, 그리고 나는에 머물 수 표시되지 않습니다 ViewController
및 tableViewController
에서 "가져 오기"데이터).
당신은 생명의 은인입니다, 감사합니다! 그것은 매력처럼 작동합니다. 방금 nextLink를 nextButtonClick에서 nextArticle.articleLink로 변경했습니다 (누군가 앞으로 이것을 필요로하는 경우). 도움을 주셔서 감사합니다. – EdouM
나는 대답을 다시 받았다. – EdouM