文本字段值不存储在字符串中

时间:2012-09-14 05:34:16

标签: iphone objective-c ios xcode uitextfield

在我的应用中,我有很多文字字段&最后有拍照按钮。但是当我从选择照片返回时,插入的文本字段值显示为空白。

我尝试将单击照片按钮时将文本字段值存储到字符串中。当我从那里返回时,我将字符串值设置为文本fied但它显示了我的错误。

帮助我!!

-(void)ViewWillAppear
{
     if (clkph) {
             txtdate.text=[NSString stringWithFormat:@"%@",phdate];
             NSLog(@"%@",txtdate.text);
             txttime.text=[NSString stringWithFormat:@"%@",phtime];
             NSLog(@"%@",txttime.text);
         }
}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

    clkph=YES;
    phdate=[NSString stringWithFormat:@"%@",txtdate];
    NSLog(@"%@",phdate);
    phtime=[NSString stringWithFormat:@"%@",txttime];
    NSLog(@"%@",phtime);
}

2 个答案:

答案 0 :(得分:2)

这样做,因为我假设phdate和phtime为UITextField:

if (clkph) {
         txtdate.text=[NSString stringWithFormat:@"%@",phdate];
          NSLog(@"%@",txtdate.text);
          txttime.text=[NSString stringWithFormat:@"%@",phtime];
          NSLog(@"%@",txttime.text);
     }

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

  clkph=YES;
  phdate=[NSString stringWithFormat:@"%@",txtdate.text];
  [phdate retain];
  NSLog(@"%@",phdate);
  phtime=[NSString stringWithFormat:@"%@",txttime.text];
  [phtime retain];
  NSLog(@"%@",phtime);
}

答案 1 :(得分:0)

请改为尝试:

if (clkph) {
     NSString* txtdate=[NSString stringWithFormat:@"%@",phdate];
     NSLog(@"%@",txtdate);
     NSString* txttime=[NSString stringWithFormat:@"%@",phtime];
     NSLog(@"%@",txttime);
 }