我为我的工作流程的一部分制作了一个测试应用程序。我想要实现的是一种向用户展示他们正在为 Word 风格的游戏输入的内容的奇特方式。
目前这是方法,但可能有更简单/更好的路线。我有一个UITextField
未向用户显示的,键盘显示在viewDidLoad
. 我想要发生的是每次在键盘上按下一个字母时,都会将显示大写字母的新拼贴添加到上方的屏幕区域,即“W”,然后另一个字母将意味着添加了另一个拼贴,即“I”旁边以前的...
我已经设置了一个UICollectionView
带有标签的自定义单元格,仅此而已。VC 是UICollectionView
. UITextField
也有其设置delegate
为self
(VC)。
我无法弄清楚如何让瓷砖(单元格)创建每个字母。
#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 to use a custom UICollectionViewCell, which will hold an image and its label
//
WordCVCell *cell = [cv dequeueReusableCellWithReuseIdentifier:kCellID forIndexPath:indexPath];
// make the cell's title the actual NSIndexPath value
NSString *lastLetter = [self.typedWord substringFromIndex:[self.typedWord length] - 1];
cell.label.text = lastLetter;
return cell;
}