I call a UIAlertController from a ViewController. When I press Ok in the UIAlertController will prompt another OK dialog.
Now the problem is when I clicked on the Ok button from the dialog, I able to exit the UIAlertController but what i want is exit the UIAlertController and refresh the primary ViewController.
Can any one help me out? :(
- (IBAction)btnAddDidPressed:(id)sender {
AddCashValueVC *addCashValueVC = [storyboard instantiateViewControllerWithIdentifier:@"addCashValueVC"];
alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"nav_Add_Credit", nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
[alertController setValue:addCashValueVC forKey:@"contentViewController"];
[self presentViewController:alertController animated:YES completion:nil];
}
Above is the Primary ViewController. Show how i call the UIAlertController.
- (IBAction)btnProceedDidPressed:(id)sender {
[self convertCashValue];
[self dismissKeyboard];
}
-convertCashValue:{
self->alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"msg_App", nil) message:[result objectForKey:@"msg"] preferredStyle:UIAlertControllerStyleAlert];
self->cashValueVC.update= YES;
UIAlertAction *openAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"btn_Ok", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
CashValueVC *cashVC = [[CashValueVC alloc] initWithNibName:nil bundle:nil];
[self dismissViewControllerAnimated:YES completion:^{
[cashVC viewDidLoad];
[cashVC viewWillAppear:YES];
[cashVC.tableView reloadData];
}];
}];
[self->alertController addAction:openAction];
[self presentViewController:self->alertController animated:YES completion:nil];
}
Above is the another UIAlertController in UIAlertController.
Following code firing one OK dialog and after tapping OK, fire another one and if tapped OK - tableview updates on main thread:
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *table;
@property (strong, nonatomic) NSArray *array; //table view dataSource
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
// update button tapped
- (IBAction)action:(id)sender {
//changing table data source
_array = @[
@"afasfasf",
@"afasfasf",
@"afasfasf",
@"afasfasf",
@"afasfasf",
@"afasfasf",
@"afasfasf"
];
//alert controllers
UIAlertController *firstAlertController = [UIAlertController alertControllerWithTitle:@"First alert"
message:nil
preferredStyle:UIAlertControllerStyleAlert];
UIAlertController *secondAlertController = [UIAlertController alertControllerWithTitle:@"Second alert"
message:nil
preferredStyle:UIAlertControllerStyleAlert];
//Actions
UIAlertAction *firstControllerOKAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
//firing second dialog
[self presentViewController:secondAlertController animated:YES completion:nil];
}];
UIAlertAction *secondControllerOKAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
//calling on main thread table view update
dispatch_async(dispatch_get_main_queue(), ^{
[self.table reloadData];
});
}];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action) {}];
//adding actions to first dialog
[firstAlertController addAction:firstControllerOKAction];
[firstAlertController addAction:cancel];
//adding actions to second dialog
[secondAlertController addAction:secondControllerOKAction];
[secondAlertController addAction:cancel];
//firing first dialog
[self presentViewController:firstAlertController animated:YES completion:nil];
}
//delegate and datasource methods
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
[tableView registerClass:UITableViewCell.class forCellReuseIdentifier:@"23"];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"23"];
cell.textLabel.text = _array[indexPath.row];
return cell;
}
- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _array.count;
}
@end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.