【问题标题】:Retrieving index path from table view从表视图中检索索引路径
【发布时间】:2013-10-13 19:05:30
【问题描述】:

我正在尝试通过将数组中的对象替换为从警报视图返回的文本来替换它。

到目前为止我有:

int selected = indexPath.row;

对于我的 alertview 委托方法。

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (alertView.tag == 1) {
        [myMutableArray replaceObjectAtIndex:selected withObject:[[alertView textFieldAtIndex:0] text]];
        [_tableView reloadData];
    }
}

我不断收到错误

从“NSInteger”(又名“long”)分配给“NSInteger *”(又名“long *”)的指针转换不兼容的整数

【问题讨论】:

  • 这是你的全部代码吗?你在哪里初始化 NSMutableArray?如果可能,请发布您的所有代码。
  • 如果回答对您的问题有帮助,请标记。

标签: ios xcode uitableview nsmutablearray uialertview


【解决方案1】:

您看到的错误是因为您在 NSInteger 变量之前的某个位置放置了 *

【讨论】:

    【解决方案2】:

    在不知道其余代码是什么样子的情况下,您可以在 ViewController.m 文件中进行尝试。它设置标签的文本,并在按下“确定”按钮时用警报视图中的文本替换可变数组中的对象。

    #import "ViewController.h"
    
    @interface ViewController () <UIAlertViewDelegate>
    
    @property (strong,nonatomic) NSMutableArray *mutArray;
    @property (weak,nonatomic) IBOutlet UILabel *label;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        NSArray *array = @[@"item1",@"item2",@"item3"];
        self.mutArray = [[NSMutableArray alloc] init];
        self.mutArray = [array mutableCopy];
    }
    
    - (IBAction)showAlert:(id)sender {
    
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"My Alert Example"
                                                        message:@"message here"
                                                       delegate:self
                                              cancelButtonTitle:@"Cancel"
                                              otherButtonTitles:@"OK",nil];
    
        alert.alertViewStyle = UIAlertViewStylePlainTextInput;
    
        [alert show];
    }
    
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    
        int selected = 1;
    
        if (buttonIndex != alertView.cancelButtonIndex) {
            NSLog(@"ok button");
            UITextField *textField = [alertView textFieldAtIndex:0];
            self.label.text = textField.text;
            [self.mutArray replaceObjectAtIndex:selected withObject:textField.text];
            NSLog(@"mutArray is %@",self.mutArray);
        } else {
            NSLog(@"cancel button");
        }
    }
    
    @end
    

    由于您使用的是 UITableView,因此在您的情况下,您将使用 int selected = indexPath.row 而不是 int selected = 1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-13
      • 1970-01-01
      • 2011-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多