ios - Using a CollectionView to add a tile effect when the user types -
i have test application have made part of workflow. trying achieve fancy way of showing user typing word styled game.
at moment approach there easier/better route. have uitextfield
not shown user , keyboard shown on viewdidload
. trying have happen each time letter pressed on keyboard new tile showing letter capitalised added screen area above i.e. 'w', letter mean tile added i.e. 'i' next previous...
i have setup uicollectionview
, custom cell label in, all. vc datasource of uicollectionview
. uitextfield
has delegate
set self
(the vc).
i cannot work out how have tiles (cells) created each letter.
#pragma mark - #pragma mark - key board delegate methods -(bool)textfield:(uitextfield *)textfield shouldchangecharactersinrange:(nsrange)range replacementstring:(nsstring *)string { nslog(@"%s",__pretty_function__); nsstring *lastlettertyped = [textfield.text substringfromindex:[textfield.text length] - 1]; [self.wordarray addobject:lastlettertyped]; [self.tilecollectionview reloaddata]; return yes; } #pragma mark - #pragma mark - collection view data source methods -(nsinteger)collectionview:(uicollectionview *)collectionview numberofitemsinsection:(nsinteger)section { return 3; } -(uicollectionviewcell *)collectionview:(uicollectionview *)cv cellforitematindexpath:(nsindexpath *)indexpath { // we're going use custom uicollectionviewcell, hold image , label // wordcvcell *cell = [cv dequeuereusablecellwithreuseidentifier:kcellid forindexpath:indexpath]; // make cell's title actual nsindexpath value nsstring *lastletter = [self.typedword substringfromindex:[self.typedword length] - 1]; cell.label.text = lastletter; return cell; }
your
-(nsinteger)collectionview:(uicollectionview *)collectionview numberofitemsinsection:(nsinteger)section { return 3; }
should read
-(nsinteger)collectionview:(uicollectionview *)collectionview numberofitemsinsection:(nsinteger)section { [self.wordarray count]; }
this trigger following same number of times there objects in array.
-(uicollectionviewcell *)collectionview:(uicollectionview *)cv cellforitematindexpath:(nsindexpath *)indexpath { // we're going use custom uicollectionviewcell, hold image , label // wordcvcell *cell = [cv dequeuereusablecellwithreuseidentifier:kcellid forindexpath:indexpath]; // make cell's title actual nsindexpath value nsstring *lastletter = [self.wordarray objectatindex:indexpath.row]; cell.label.text = lastletter; return cell; }
Comments
Post a Comment