xcode6 - Collection View and String type help in Swift -



xcode6 - Collection View and String type help in Swift -

i trying send pictures collection view, similar way in list tutorial, working images, not text. error in code say:

picture.append(picture.image)

the error says [string] not have fellow member named 'image'.

how should approach if cant utilize string? other type should use?

i getting error in cellforitematindexpath section. code:

func collectionview(collectionview: uicollectionview, cellforitematindexpath indexpath: nsindexpath) -> uicollectionviewcell { var cell = collectionview.dequeuereusablecellwithreuseidentifier("cell", forindexpath: indexpath) cell cell.imageview.image = uiimage(named: picture[indexpath.row]) homecoming cell }

in getting error saying cell @ end of first line undeclared, not sure or how supposed declare this, since have other projects collection views , didn't need declare anything.

please allow me know if can help, thanks!

i believe see source of errors. i'll cover each error below, , suggestions on how alleviate them.

picture.append(picture.image)

error: [string] not have fellow member named 'image'.

since acquiring fellow member "image" via dot-notation object "picture", error suggests "picture" (the lowercase one) array of standard swift strings.

swift strings not have property named "image" in them, error pointing out. if want filename images, can left string.

then, when phone call in next snippet of code, pulls out filename string , passes uiimage initializer.

from looking @ code in next snippet, think might have meant this:

let image = "someimage.png" //the filename image append array. var image = [string]() //an array of strings hold filenames images. picture.append(image)

in case have array called "picture", , append filename string (stored string named "image") array.

var cell = collectionview.dequeuereusablecellwithreuseidentifier("cell", forindexpath: indexpath) cell

error: utilize of undeclared type 'cell'

this says cell type undeclared. have not used uicollectionview yet, understanding, info type uicollectionviewcell, not "cell" (the capital one). have type uicollectionviewcell.

from research, appears uicollectionviewcell not have fellow member named imageview. in case, write custom subclass of uicollectionviewcell named cell, , give property named imageview, like:

class cell: uicollectionviewcell { var imageview = uiimageview() } cell.imageview.image = uiimage(named: "someimage.png")

one note code above, renamed property "imageview" (now starting lowercase 'i'). apple suggests name types (like uicollectionviewcell or string) capital letters @ beginning. functions , properties should start lowercase letters conform coding standard.

then can wire imageview storyboard or other part of code property, , set uicollectionviewcell "cell" type, , set imageview property.

for more info on using uicollectionviews, take @ @ brian j coleman's post "tutorial: collection view using swift"

i hope reply has been of help. luck on learning swift!

swift xcode6

Comments

Popular posts from this blog

c - Compilation of a code: unkown type name string -

java - Bypassing "final local variable defined in an enclosing type" -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -