2012-07-25 76 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;上的斷點來查看賦值過程中的值。)