无法从数组中获取indexPath.row(错误indexPath未声明)?

发布于 2024-10-03 18:56:41 字数 1227 浏览 1 评论 0原文

我在我的 .h 中声明了一个 NSArray,

@interface DevicePreferencesController : UITableViewController < UIAlertViewDelegate >{
    NSArray *plist;
    UITextField *deviceName;
}

这个数组用于从 URL 加载 plist 数据

,这是我得到的 plist,

plist:(
        {
        category = 11;
        id = 1;
        name = light1;
    },
        {
        category = 11;
        id = 5;
        name = window;
    },
        {
        category = 12;
        id = 2;
        name = dimmer2;
    },
        {
        category = 23;
        id = 3;
        name = win;
    }
)

我通过 tableView 显示它

,如果我选择单元格,

它将弹出一个带有文本字段的警报视图,它可以重命名plist中的数据

这是alertView的按钮操作

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if ([alertView tag]==1) {
        if (buttonIndex == 1){
            [request setPostValue:[[self.plist objectAtIndex:indexPath.row] valueForKey:@"id"]  forKey:@"id"];
            [request setPostValue:deviceName.text  forKey:@"name"];
            [request startSynchronous];
        }
    }
}

但是我在这里遇到错误“indexPath”未声明

为什么 ? plist是一个数组,为什么我不能从数组中获取indexPath???

I declared a NSArray in my .h

@interface DevicePreferencesController : UITableViewController < UIAlertViewDelegate >{
    NSArray *plist;
    UITextField *deviceName;
}

This array is use to load a plist data from URL

and this is the plist I got

plist:(
        {
        category = 11;
        id = 1;
        name = light1;
    },
        {
        category = 11;
        id = 5;
        name = window;
    },
        {
        category = 12;
        id = 2;
        name = dimmer2;
    },
        {
        category = 23;
        id = 3;
        name = win;
    }
)

I show It by a tableView

and if I selected the cell

It will pop up an alertView with a textField,it can rename the data in the plist

And here is the button action for alertView

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if ([alertView tag]==1) {
        if (buttonIndex == 1){
            [request setPostValue:[[self.plist objectAtIndex:indexPath.row] valueForKey:@"id"]  forKey:@"id"];
            [request setPostValue:deviceName.text  forKey:@"name"];
            [request startSynchronous];
        }
    }
}

But I got error here "indexPath" undeclared !

Why ? plist is an array ,why can't I get indexPath from an array ???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

℉絮湮 2024-10-10 18:56:41

'indexPath' 不是您的变量,所以这是因为它未声明。您应该将 tableview didselectedrow 方法中的 indexPath 存储到本地变量,并在alertView委托方法中使用它。

'indexPath' is not your variable, so that is because it's undeclared. You should store the indexPath in the tableview didselectedrow method, to a local variable, and use it in the alertView delegate method.

晨光如昨 2024-10-10 18:56:41

indexPath 可作为 TableView 的 Delegate 和 DataSource 方法的一部分使用。您的类中是否有一个名为 indexPath 的变量作为全局变量或成员变量?

indexPath is available as part of TableView's Delegate and DataSource methods. Do you have a variable named indexPath as a global variable or as a memeber variable in your class?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文