我目前正在制作一个自定义 UITableView 单元格,如下所示。自定义 UITableViewCell 位于我从另一个 ViewController 调用的它自己的 nib 文件中。(像这样)
// 注册视图控制器.m
//Sets number of sections in the table
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
// Sets the number of rows in each section.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
//Loads both Custom cells into each section
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//Registration Cell
static NSString *CellIdentifier = @"CustomRegCell";
static NSString *CellNib = @"LogInCustomCell";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellNib owner:self options:nil];
cell = (UITableViewCell *)[nib objectAtIndex:0];
}
//Registration Button
static NSString *CellButtonIdentifier = @"CustomSubmitCell";
static NSString *CellButtonNib = @"LogInSubmitButton";
UITableViewCell *cellButton = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellButtonIdentifier];
if (cellButton == nil) {
NSArray *nibButton = [[NSBundle mainBundle] loadNibNamed:CellButtonNib owner:self options:nil];
cellButton = (UITableViewCell *)[nibButton objectAtIndex:0];
}
if (indexPath.section == 0) {
cell.selectionStyle = UITableViewCellSelectionStyleNone; //Stops the UITableViewCell from being selectable
[self registrationControll];
//TODO: call method that controls this cell
return cell;
}
if (indexPath.section == 1) {
cellButton.selectionStyle = UITableViewCellSelectionStyleNone; //Stops the UITableViewCell from being selectable
return cellButton;
}
return nil;
}
它有四个文本字段,我想将可以输入的字符串的大小限制为五个。(到目前为止,我只尝试使用第一个文本字段,但它甚至没有输入 textField:shouldChangeCharactersInRange:replacementString: 委托方法(在调试应用程序时发现)这是我试图限制的部分的代码可以输入的字符数量。
// 注册视图控制器.m
//textField:shouldChangeCharactersInRange:replacementString:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
int length = [regFieldOne.text length] ;
if (length >= MAXLENGTH && ![string isEqualToString:@""]) {
regFieldOne.text = [regFieldOne.text substringToIndex:MAXLENGTH];
return NO;
}
return YES;
}
我想我已经将我的错误限制在两件事之一。也许我没有正确设置界面生成器中的所有内容。
或者它与委派有关......我对此有一个大致的了解,这就是为什么我认为问题可能在这里,但是对于如此复杂的文件结构,我不确定这是如何或是否正确。
任何帮助、解释、建议等将不胜感激。