ios - 全局访问 UIalertview 中的文本字段数据

标签 ios xcode nsstring uitextfield uialertview

我创建了一个带有文本字段的警报 View ,当我选择按钮时必须访问插入文本字段的详细信息。这是我的代码

-(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 我创建了属性并合成了它..但我不知道我在哪里缺少它...

最佳答案

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

(否则,请在 qtystr=str; 上使用断点来查看赋值期间的值。)

关于ios - 全局访问 UIalertview 中的文本字段数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11648248/

相关文章:

php - Facebook。可以发私信吗?

ios - 新的 EventKit EKCalendar 不会创建?

Objective-C 中 Java 的 TreeMap 替代品?

ios - 人们为什么倾向于将NSURL存储为NSString

ios - UITableView 不滚动到底部

ios - MKPolyline 未在 map 上绘制。我该如何解决这个问题?

ios - TableViewController 在搜索时填充,但不会加载初始 View

iPhone模拟器失败

iphone - 如何找出一个图像是否存在于一个包中?

objective-c - [__NSCFSet stringByAppendingFormat :]: unrecognized selector sent to instance