【发布时间】:2010-12-30 05:58:05
【问题描述】:
我正在尝试从警报视图中获取文本并将其添加到我的可变数组以在表格视图中列出。我意识到几个月前发布了一个类似的问题,但我不明白如何利用给定的答案。
-(IBAction)insert {
UIAlertView* dialog = [[UIAlertView alloc] init];
[dialog setDelegate:self];
[dialog setTitle:@"Enter Name"];
[dialog setMessage:@" "];
[dialog addButtonWithTitle:@"Cancel"];
[dialog addButtonWithTitle:@"OK"];
UITextField *nameField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
[nameField setBackgroundColor:[UIColor whiteColor]];
[dialog addSubview:nameField];
[dialog show];
[data addObject:[nameField text]];
[mainTableView reloadData];
但是我的应用程序崩溃了,因为它说我试图在索引 0 处插入一个 nil 对象。我做错了什么?
编辑:好的,我想我缺少一种处理警报视图的方法。所以我发现了这个:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *buttonTitle=[alertView buttonTitleAtIndex:buttonIndex];
if([buttonTitle isEqualToString:@"Cancel"]) {
return;
}
else if([buttonTitle isEqualToString:@"Ok"]) {
[data addObject:nameField.text];
}
现在我只需要连接各个部分,但不确定如何。
【问题讨论】:
标签: iphone objective-c uialertview