'索引路径'未声明(在此函数中首次使用)
我有以下错误。 “indexPath”未声明(在此函数中首次使用)。
代码。 didSelectRowAtIndexPath
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleWhiteLarge];
cell.accessoryView = spinner;
[spinner startAnimating];
[spinner release];
[self performSelector:@selector(pushDetailView:) withObject:tableView afterDelay:0.1];
}
pushDetailView
- (void)pushDetailView:(UITableView *)tableView {
// Push the detail view here
[tableView deselectRowAtIndexPath:indexPath animated:YES];
//load the clicked cell.
DetailsImageCell *cell = (DetailsImageCell *)[tableView cellForRowAtIndexPath:indexPath];
//init the controller.
AlertsDetailsView *controller = nil;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
controller = [[AlertsDetailsView alloc] initWithNibName:@"DetailsView_iPad" bundle:nil];
} else {
controller = [[AlertsDetailsView alloc] initWithNibName:@"DetailsView" bundle:nil];
}
//set the ID and call JSON in the controller.
[controller setID:[cell getID]];
//show the view.
[self.navigationController pushViewController:controller animated:YES];
}
我认为这是因为我没有将 indexPath 值从 didSelectRowAtIndexPath
解析为 pushDetailView
但我不这样做不知道如何解决这个问题。
有人可以建议吗?
谢谢。
I have the following error. 'indexPath' undeclared (first use in this function).
Code.
didSelectRowAtIndexPath
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleWhiteLarge];
cell.accessoryView = spinner;
[spinner startAnimating];
[spinner release];
[self performSelector:@selector(pushDetailView:) withObject:tableView afterDelay:0.1];
}
pushDetailView
- (void)pushDetailView:(UITableView *)tableView {
// Push the detail view here
[tableView deselectRowAtIndexPath:indexPath animated:YES];
//load the clicked cell.
DetailsImageCell *cell = (DetailsImageCell *)[tableView cellForRowAtIndexPath:indexPath];
//init the controller.
AlertsDetailsView *controller = nil;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
controller = [[AlertsDetailsView alloc] initWithNibName:@"DetailsView_iPad" bundle:nil];
} else {
controller = [[AlertsDetailsView alloc] initWithNibName:@"DetailsView" bundle:nil];
}
//set the ID and call JSON in the controller.
[controller setID:[cell getID]];
//show the view.
[self.navigationController pushViewController:controller animated:YES];
}
I think it's because I'm not parsing the indexPath value from didSelectRowAtIndexPath
to pushDetailView
but I don't know how to approach this.
Could someone please advise?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是您的
pushDetailView:
方法在其范围内没有indexPath
变量。相反,
您应该像这样创建您的方法:
然后在方法范围内声明
indexPath
。然后,在
didSelectRowAtIndexPath
方法中,替换以下代码:
这使用
GCD
在延迟后执行代码,而不是performSelector: withObject :afterDelay:
这里是 一篇不错的文章解释了为什么有时最好选择这种方法The problem is that you
pushDetailView:
method has noindexPath
variable on it's scope.Instead of
You should make your method like this:
and then
indexPath
would be declared on the method scope.Then, inside your
didSelectRowAtIndexPath
method, replacefor the code bellow:
This uses
GCD
to execute the code after a delay, instead of theperformSelector: withObject :afterDelay:
and here is a nice post explaining why sometimes is better to opt for this aproach由于您需要提供两个参数并在延迟后执行,将两个参数打包在 NSDictionary 中并传递它:
或者如 @Felipe 建议的那样,使用 GCD。
Since you need to provide two arguments and perform after a delay package both arguments in an NSDictionary and pass it:
Or as @Felipe suggests, use GCD.