Xcode 6 GM에서 스토리 보드를 사용하여 신속하게 앱을 개발 중입니다. 내 viewcontroller에서 모든 뷰를 드래그 앤 드롭하여 관련 viewcontroller 파일의 IBOutlet과 연결하면 해당 콘센트는 항상 viewDidLoad에서 nil이고 버튼 제목 변경과 같은 콘센트와 상호 작용하려고하면 항상 BAD_INSTRUCTION 오류가 발생합니다. 그 참조 콘센트가 항상 nil이고 내가 왜 이해할 수 없기 때문에. 스토리 보드의 viewcontroller가 사용자 정의 클래스 옵션 아래의 ID 관리자의 viewcontroller 파일에 의해 소유되었는지 확인했습니다 .. Xcode와 누군가의 문제입니까? 다른 문제가 발생하거나 잘못된 것이 있습니다.Xcode 6 GM 스토리 보드 아울렛은 항상 Nothing
편집 1 :
이
import UIKit
클래스의 ViewController를 출시되는 첫 번째의 ViewController입니다 : UIViewController에 {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let vc = segue.destinationViewController as TableViewController
vc.prepare(/*initializing things..*/)
}
// 그리고이 내있는 tableview 콘센트와의 ViewController가 맞춤 셀
import UIKit
클래스 TableViewController :의 UIViewController, UITableViewDelegate, UITableViewDataSource는 {
@IBOutlet var tableView: UITableView!
//this array contains the date to display in cells and in viewDidLoad is correctly initialized with all the right data..
private var toVisualize:[Visualizable] = []
override func viewDidLoad() {
super.viewDidLoad()
/*I need to initialize the tableview even if it's an outlet rightly connected to the storyboard because it's always nil when viewDidLoad is called*/
self.loadArticles()
self.tableView = UITableView(frame: self.tableView.frame, style: UITableViewStyle.Plain)
//navigationController?.hidesBarsOnSwipe = true
self.tableView.delegate = self
self.tableView.dataSource = self
self.tableView.allowsSelection = true
var cell = UINib(nibName: "MyCell", bundle: nil)
/*first I've used a prototype cell defined in the storyboard and a class with the related outlets and all connected in the right way but the result was a blank screen so I've tried to use a xib file to define the layout of my custom cell and the tableview started showing my cells.. but still I can't figure out why the tableview is nil*/
self.tableView.registerNib(cell, forCellReuseIdentifier: "Cell")
//self.tableView.registerClass(CellaTableViewCell.classForCoder(), forCellReuseIdentifier: "Cell")
self.view.addSubview(self.tableView)
self.tableView.reloadData()
// Do any additional setup after loading the view.
}
func prepare(/*preparing function used from first view controller..*/)->()
{
//this func is not changing anything because I've added it later..
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//this function is correctly working and showing the cells when the tableview is initialized
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = self.tableView?.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as MyCell
var toLoad = self.toVisualize[indexPath.row].getVisualizableProperties()
cell.loadItem(toLoad.title, descr: toLoad.descr, date: toLoad.date)
if let URL = toLoad.thumbUrl
{
var image = self.imageCache[URL]
if(image == nil) {
// If the image does not exist, we need to download it
var imgURL: NSURL = NSURL(string: URL)
// Download an NSData representation of the image at the URL
let request: NSURLRequest = NSURLRequest(URL: imgURL)
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler: {(response: NSURLResponse!,data: NSData!,error: NSError!) -> Void in
if error == nil {
image = UIImage(data: data)
// Store the image in to our cache
self.imageCache[URL] = image
dispatch_async(dispatch_get_main_queue(), {
if let cellToUpdate = tableView.cellForRowAtIndexPath(indexPath) as? MyCell {
cellToUpdate.thumbnail?.image = image
}
})
}
else {
println("Error: \(error.localizedDescription)")
}
})
}
else {
dispatch_async(dispatch_get_main_queue(), {
if let cellToUpdate = tableView.cellForRowAtIndexPath(indexPath) as? MyCell {
cellToUpdate.thumbnail?.image = image
}
})
}
}
return cell
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView!,heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat
{
return 120.0
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.toVisualize.count
}
}
먼저 난 항상있는 viewDidLoad에 nil을 한 TablewViewController 프로그램 내 출구의 tableview를 밀어 presentViewController을 사용 한 후 내가 사용하려고했습니다 내 ViewController의 버튼의 "트리거 된 후행"액션은 TableViewController (ViewController는 뷰에 4 개의 버튼이있어 모두 TableViewController를 표시합니다. 특별하거나 이상하지 않음) 및 tableview가 초기화되기 시작한 후 ' tableview의 init 메소드를 주석 처리했습니다. 및 위임 설정 (대리인 및 dataSource는 이미 스토리 보드에 설정되어 있음) 결과는 아무것도 보이지 않는 빈 화면입니다. 스토리 보드 및 다양한 식별자와의 모든 연결을 두 번 확인 했으므로 모두 제대로 설정되었습니다. 문제를
당신이 당신의 코드를 게시 할 수 있습니까? –
내 코드를 변경했습니다. 먼저 'code'presentViewController (vc, animated : true, completed : nil)'코드 '를 사용하여 프로그래밍 방식으로 viewcontroller를 푸시하고있었습니다. 이제 버튼 클릭에 액션을 추가했습니다. segue 지금은 tableview 내 콘센트 초기화되지 및 nil 있지만 이제 문제는 경우에만 xib 파일을 사용하여 셀 레이아웃을 정의하고 프로토 타입 셀에 직접 정의 된 테이블 뷰의 내 사용자 지정 셀을 작동하는 것입니다. 그것과 관련된 모델 클래스 및 해당 콘센트와 스토리 보드의 tableview .. – user3676870
콘센트가 올바르게 초기화되어 있고 그들과 상호 작용할 수있는 "트리거 된 뒤덮기"옵션을 사용하면 프로그래밍 방식으로 viewcontrollers를 사용하면 문제가 발생한다고 생각합니다. 여전히 초기화되지 않은 경우 tableview 내 사용자 지정 셀 이벤트를 표시하지 않습니다 (결코 호출 cellForRowAtIndexPath) – user3676870