2016-04-16 28 views
7

Ho due ViewControllers, uno è GoalsViewController e l'altro è AddNewGoalViewController.Come risolvere il problema Disappearing/Invisible/Empty UITableViewCells in Swift?

GoalsViewController è utile per eliminare obiettivi (celle) e aggiungere nuovi obiettivi (celle). C'è un UITableView e un pulsante, Aggiungi nuovo obiettivo. Quando l'utente preme il pulsante Aggiungi nuovo obiettivo, passerà a AddNewGoalViewController. In AddNewGoalViewController gli utenti selezioneranno allenamento, notifiche (quante volte vogliono essere avvisati) e quanto vogliono correre, camminare o fare qualsiasi altro lavoro.

Ho controllato a tutorial (fare clic sulla parola "tutorial" per controllarlo) ed è stato utile. Il problema è che sta implementando celle vuote. Download il mio progetto per controllarlo meglio.

+2

Davvero non hai ricevuto la tua domanda. Dove stai affrontando un problema su tableview o addgoals e qual è il problema –

+0

C'è stato un problema? Quale problema? – FredericP

+1

Dovresti mostrare il tuo codice (può essere caricato su google drive e fornire un link) e indicare esattamente qual è il problema che stai affrontando. – Mathews

risposta

3

EDIT: Dopo aver trascorso molto tempo a esaminare il progetto, ho riscontrato il problema.

Fare clic sul file Main.Storyboard. Clicca sull'Ispettore File. Deseleziona Classi di dimensioni. Fatto. Il tuo progetto funziona!

Questo sembra essere un bug XCode. Se controlli nuovamente Classi di Dimensioni, il tuo progetto dovrebbe ancora funzionare.

La correzione è quindi di deselezionare e quindi selezionare Classi dimensioni in File Inspector del file Main.storyboard.

TUTTAVIA: Il mio consiglio sintassi è ancora valida, rende il codice più pulito:

Beh, avete controllato the solution of the exercise?

C'è un link alla fine della pagina;)

prima differenza:

var workouts = [Workout]() 

var numbers = [Workout]() 

func loadSampleMeals() { 
    let workouts1 = Workout(name: "Run", number: "1000")! 

    let workouts2 = Workout(name: "Walk", number: "2000")! 

    let workouts3 = Workout(name: "Push-Ups", number: "20")! 

    workouts += [workouts1, workouts2, workouts3] 
    numbers += [workouts1, workouts2, workouts3] 
} 

dovrebbe essere:

var workouts = [Workout]() 

func loadSampleMeals() { 
    let workouts1 = Workout(name: "Run", number: "1000")! 

    let workouts2 = Workout(name: "Walk", number: "2000")! 

    let workouts3 = Workout(name: "Push-Ups", number: "20")! 

    workouts += [workouts1, workouts2, workouts3] 
} 

seconda differenza:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    // Table view cells are reused and should be dequeued using a cell identifier. 
    let cellIdentifier = "DhikrTableViewCell" 
    let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! GoalsTableViewCell 

    // Fetches the appropriate meal for the data source layout. 
    let dhikr = workouts[indexPath.row] 
    let number = numbers[indexPath.row] 


    cell.nameLabel.text = dhikr.name 
    cell.numberLabel.text = number.number 
    //cell.photoImageView.image = dhikr.photo 
    //cell.ratingControl.rating = dhikr.rating 

    return cell 
} 

dovrebbe essere:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    // Table view cells are reused and should be dequeued using a cell identifier. 
    let cellIdentifier = "DhikrTableViewCell" 
    let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! GoalsTableViewCell 

    // Fetches the appropriate meal for the data source layout. 
    let dhikr = workouts[indexPath.row] 


    cell.nameLabel.text = dhikr.name 
    cell.numberLabel.text = dhikr.number 
    //cell.photoImageView.image = dhikr.photo 
    //cell.ratingControl.rating = dhikr.rating 

    return cell 
} 

P.S .:

class Workout { 
    // MARK: Properties 

    var name: String 
    //var notifications: Int 
    var number: Int 

    // MARK: Initialization 

    init?(name: String, number: Int) { 
     // Initialize stored properties. 
     self.name = name 
     //self.notifications = notifications 
     self.number = number 

     // Initialization should fail if there is no name or if the rating is negative. 
     if name.isEmpty || number < 0{ 
      return nil 
     } 
    } 
} 

number sarà mai < 0, Forse volevi dire == 0?.

+0

Funziona perfettamente (Y), grazie amico mio. – Emm

+1

@EminEmini Il mio piacere di aiutare ^^ – Coder1000