Uitableview 在Tableview中从textfield获取要标记的值

Uitableview 在Tableview中从textfield获取要标记的值,uitableview,ios5,xcode4.2,uitextfield,Uitableview,Ios5,Xcode4.2,Uitextfield,我在一个应用程序中工作,其中我有tableview,其中包含文本字段和标签。现在我想要的是,当我在有分数的文本字段中输入文本时,它应该计算一些东西,并在tableview标签中为该单元格提供结果百分比。 下面是我如何在CellForRowatineXpath中创建tetfield和标签的 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

我在一个应用程序中工作,其中我有tableview,其中包含文本字段和标签。现在我想要的是,当我在有分数的文本字段中输入文本时,它应该计算一些东西,并在tableview标签中为该单元格提供结果百分比。 下面是我如何在CellForRowatineXpath中创建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;
 }
对于计算,我使用以下代码

-(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];  
   }

如何才能解决这个问题

我有一个好主意,如果不是因为你的问题,我肯定不会尝试,所以谢谢你;)

如果文本字段不需要任何其他委托方法,除了设置标签,您可以通过这种方式解决问题

在UILabel上创建一个类别

@interface UILabel (CopyTextField) <UITextFieldDelegate>
@end


@implementation UILabel (CopyTextField)
-(void)textFieldDidEndEditing:(UITextField *)textField
{
    // do whatever you want with your textfield's text and set self.text to the value
    self.text = textField.text; // here I'm just copying the text as it is
}

我有一个好主意,如果不是因为你的问题,我肯定不会尝试,所以谢谢你;)

如果文本字段不需要任何其他委托方法,除了设置标签,您可以通过这种方式解决问题

在UILabel上创建一个类别

@interface UILabel (CopyTextField) <UITextFieldDelegate>
@end


@implementation UILabel (CopyTextField)
-(void)textFieldDidEndEditing:(UITextField *)textField
{
    // do whatever you want with your textfield's text and set self.text to the value
    self.text = textField.text; // here I'm just copying the text as it is
}

解决什么?我们需要先解决问题,然后才能解决它…解决什么?我们需要先解决一个问题,然后才能解决它…非常感谢,我已经尝试了代码,它按照我想要的方式工作,我可以用同样的方式找到分数吗,因为我需要根据同一行上的标签lblPercent找到分数。使用此解决方案,您的文本字段只能有一个委托,如果在更改textField的值时需要更改多个对象,则应引用这些对象(例如属性),并将控制器用作委托。然后在-(void)textfielddidediting:(UITextField*)textField实现中,您需要进行所需的所有更改。非常感谢,我已经尝试了该代码,它按照我想要的方式工作,我可以用同样的方法查找成绩吗?因为我需要根据同一行上的标签LBL百分比来查找成绩。使用此解决方案,您的textfield只能有一个代理,如果在更改textfield的值时需要更改多个对象,则应引用这些对象然后在-(void)textfielddidediting:(UITextField*)textField实现中,您需要进行所需的所有更改。