0
我想驗證在customtableview單元格中添加的文本字段中的文本。我可以獲取文本並進行驗證,但無法設置邊框顏色。我甚至嘗試重新加載整個tableview。提前致謝。如何在UITableviewCustomCell中爲文本字段添加邊框顏色 - iPhone
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.selectedRow inSection:0];
MyCustomTableviewCell *cell = (MyCustomTableviewCell*)[self.myTableView cellForRowAtIndexPath:indexPath];
UITextField *textField = cell.txtfield;
self.string = textField.text;
if (self.string.length < 8)
{
textField.layer.borderColor = [UIColor redColor].CGColor;
self.showTxtFieldinRed = YES;
}
else
{
textField.layer.borderColor = [UIColor clearColor].CGColor;
self.showTxtFieldinRed = NO;
}
NSArray *indexPathArray = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:self.selectedRow inSection:0]];
[self.myTableView reloadRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationAutomatic];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MyCustomCell";
MyCustomTableviewCell *cell = (MyCustomTableviewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.delegate = self;
cell.txtCVV.delegate = self;
if (cell == nil)
{
NSArray *arrayContent = [[NSBundle mainBundle] loadNibNamed:@"MyCustomTableviewCell" owner:nil options:nil];
cell = (MyCustomTableviewCell*)[arrayContent objectAtIndex:0];
cell.backgroundColor = [UIColor clearColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
if(self.selectedRow == indexPath.row)
{
cell.txtfield.layer.borderColor = [UIColor redColor].CGColor;
}
else
{
cell.txtfield.layer.borderColor = [UIColor clearColor].CGColor;
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
完成??如果有幫助,那麼標記爲正確 – 2015-03-31 09:50:26