如何调用popup当我点击在iOS单元格目标c

self.infoView.hidden = NO; self.infoView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7]; 

我想在表格视图中调用瘦

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row==0) { return; } NSMutableDictionary *Tag_Dic = [NSMutableDictionary dictionary]; [Tag_Dic setObject:[NSNumber numberWithInteger:indexPath.row] forKey:@"Tags"]; [[NSNotificationCenter defaultCenter] postNotificationName:@"MoveToNext" object:self userInfo:Tag_Dic]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setInteger:indexPath.row forKey:@"SenderTag"]; [defaults synchronize]; } 

尝试这个。 点击UITableViewCell时必须显示alertController

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ [cell.button addTarget:self action:@selector(presentAlert) forControlEvents:UIControlEventTouchUpInside]; } 

然后在presentAlertselect器中为UIAlertController编写代码。

  UIAlertController * alert= [UIAlertController alertControllerWithTitle:@"Title" message:@"message" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { }]; UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { [alert dismissViewControllerAnimated:YES completion:nil]; }]; [alert addAction:ok]; [alert addAction:cancel]; [self presentViewController:alert animated:YES completion:nil]; 

如果要在单击tableview单元格时显示警报,请在didSelectRowAtIndexPath方法中执行以下操作。

对于iOS 9和更早版本,

 UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Button1",@"Button2", nil]; alertView.delegate = self; [alertView show]; 

和用户UIAlertView的委托方法来实现你的逻辑当button被点击

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

对于iOS 9及以上版本( UIAlertView已被弃用)。

 UIAlertAction *actionOK = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { //handel when OK button is pressed. }]; UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { //handel when Cancel button is pressed. }]; UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:UIAlertControllerStyleAlert]; [alertVC addAction:actionOK]; [alertVC addAction:actionCancel]; [self presentViewController:alertVC animated:true completion:nil]; 

在ios 8.3和更早的版本中,

 - (void)saveButton { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; } 

8.4popup动作后使用UIAlertController和我已经在popup视图中创buildUITextField,并给出下面的行动,

 - (void)callAlert { UIAlertController *alert= [UIAlertController alertControllerWithTitle:@"Enter Folder Name" message:@"Keep it short and sweet" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){ //Do Some action here UITextField *textField = alert.textFields[0]; NSLog(@"text was %@", textField.text); }]; UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { NSLog(@"cancel btn"); [alert dismissViewControllerAnimated:YES completion:nil]; }]; [alert addAction:ok]; [alert addAction:cancel]; [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { textField.placeholder = @"folder name"; textField.keyboardType = UIKeyboardTypeDefault; }]; [self presentViewController:alert animated:YES completion:nil]; } 

最后在你想要的地方调用这个方法,希望它有帮助。