我在一個應用程序中工作,其中我有tableview,其中包含Textfield和Label。現在我想要的是,當我在文本框中輸入文本時,它應該計算一些東西,併爲該單元格的tableview標籤提供結果百分比。 繼承人如何在cellForRowAtIndexpath中創建tetfield和標籤。從textfield獲取值到Tableview中的標籤
- (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];
}
在如何解決這個問題?
解決什麼問題?在我們解決它之前,我們首先需要一個問題... –