2012-07-25 75 views
0

我已经创建了一个文本框和alertview其插入文本框中的细节都当我选择button.here是我的代码访问文本字段数据全球

-(IBAction)addcart:(id)sender{ 

UIAlertView *customAlertView = [[UIAlertView alloc] initWithTitle:@"Enter Your quantity" message:@"" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:@"Cancel", nil]; 

txtfield = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 40.0, 260.0, 20.0)]; 

[txtfield setBackgroundColor:[UIColor whiteColor]]; 

[txtfield setKeyboardType:UIKeyboardTypeNumberPad]; 



[customAlertView addSubview:txtfield]; 

[customAlertView show]; 

[customAlertView release]; } 

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 

if (buttonIndex == 0) 
{ 
    NSString* str=txtfield.text; 

    qtystr=str; 
} 


-(IBAction)showcontent:(id)sender{ 

NSLog(@"%@",qtystr); } 

这里qtystr,txtfield我要访问已创建属性并将其合成..但我不知道我在哪里丢失它...

回答

1

如果qtystr是属性,请在引用它时使用self.qtystr

(否则,请使用qtystr=str;上的断点来查看赋值过程中的值。)