2015-02-15 4 views
0

В моей последней функции в этом примере выбора кода Xcode генерирует ошибку «Использовать необъявленный тип» allEntries. Я просмотрел несколько сообщений по этой теме и все еще имею проблемы. Не уверен, что сделать переменную общественность вопрос здесь, так как все в том же классе.Использование проблемы с необъявленным типом

import UIKit 

class AllEntriesTableViewController: UITableViewController { 

var passedValue = "" 
var allEntries = [String]() 

override func viewDidLoad() { 
    super.viewDidLoad() 


    var user = PFUser.currentUser() 
    let event = PFObject(className:"event") 
    var query = PFQuery(className:"event") 
    query.whereKey("user", equalTo: user) 
    query.includeKey("category") 
    let category = event["category"] as NSString 
    query.findObjectsInBackgroundWithBlock { 
    (objects: [AnyObject]!, error: NSError!) -> Void in 
    if error == nil { 
    // The find succeeded. 
    self.allEntries.removeAll(keepCapacity: true) 
    // Do something with the found objects 
    for object in objects { 
     var allEnt:String = object as String 
     self.allEntries.append(allEnt) 
     //self.allEntries.append(allEnt.category) 
    } 
    } else { 
    // Log details of the failure 
    NSLog("Error: %@ %@", error, error.userInfo!) 
    } 
    } 



    // Uncomment the following line to preserve selection between presentations 
    // self.clearsSelectionOnViewWillAppear = false 

    //Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
    //self.navigationItem.rightBarButtonItem = self.editButtonItem() 
     } 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

// MARK: - Table view data source 

override func numberOfSectionsInTableView(tableView: UITableView!) -> Int { 
    // #warning Potentially incomplete method implementation. 
    // Return the number of sections. 
    return 1 
} 

override func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int { 
    // #warning Incomplete method implementation. 
    // Return the number of rows in the section. 
    return 3 
} 

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cellsForSection: [allEntries] = sections[indexPath!.section] as Array 
    return cellsForSection[indexPath!.row] as allEntries 
+1

'allEntries' - это * переменная *, а не * тип *, поэтому' let cellForSection: [allEntries] = ... 'и' ... as allEntries' не имеет никакого смысла. Что вы ожидали от этого? –

+0

пытаясь вернуть массив allEntries в качестве ячеек, я собираюсь сделать все это неправильно? – DelphiData

ответ

0

allEntries является переменной, а не класс. Поэтому литая, как и в последней строке

as allEntries 

не работает. Вы должны вернуть объект от типа UITableViewCell в cellForRowAtIndexPath.

+0

Изменен - ​​переопределение функ Tableview (Tableview: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { вар клеток: UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier ("клетка"), как UITableViewCell cell.textLabel .text = allEntries [ indexPath.row] return cell } --- но теперь дает фатальную ошибку: не удается индексировать пустой буфер (lldb) ошибка отладки в строке -> cell.textLabel! .text ....... row] – DelphiData

+0

Любые мысли или направления к ресурсам по использованию возвращаемого массива для создания таблицы - будет оценена не только метка ячейки. – DelphiData

+0

Вы должны вернуть одну ячейку, а не массив в cellForRowAtIndexPath. Я бы рекомендовал проверить руководства по программированию: [руководство] (https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TableView_iPhone/AboutTableViewsiPhone/AboutTableViewsiPhone.html) – croX

Смежные вопросы