我正在一个应用程序中工作,我有一个包含文本字段和标签的表格视图。现在我想要的是当我在具有分数的文本字段中输入文本时,它应该计算一些东西并在该单元格的表格视图标签中给我结果百分比。下面是我如何在 cellForRowAtIndexpath 中创建 tetfield 和标签。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
lblpercent = [[UILabel alloc]initWithFrame:CGRectMake(395, 5, 270, 30)];
UITextField *txtscore = [[UITextField alloc] initWithFrame: CGRectMake(306,5,100,30)];
txtscore.delegate = self;
txtscore.keyboardType = UIKeyboardTypeNumberPad;
[txtscore addTarget:self action:@selector(textFieldDone:) forControlEvents:UIControlEventEditingDidEnd];
lblpercent.text = per;
}
对于 caqlculation 我使用以下代码
-(void) textFieldDone: (id) sender
{
UITextField *field = sender;
NSLog(@"%d",i);
NSString *total = field.text;
int tot = [total intValue];
NSLog(@"The text is %d", tot);
per = [[NSString alloc] init];
if (tot == 90) {
percent=90;
}
per = [NSString stringWithFormat:@"%d",percent];
}
如何解决这个问题?