【发布时间】:2011-12-03 19:00:19
【问题描述】:
我这样做不是标准方式吗?我经常看到这种格式,但不确定为什么我的代码最终会崩溃并告诉我我正在尝试访问以前释放的实例。
任何帮助表示赞赏。
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
vcListGrades *listGradesViewController = [[vcListGrades alloc] initWithNibName:@"vcListGrades" bundle:nil];
listGradesViewController.managedObjectContext = self.managedObjectContext;
Course *sCourse = [_fetchedResultsController objectAtIndexPath:indexPath];
[listGradesViewController setCourse: sCourse];
[self.navigationController pushViewController:listGradesViewController animated:YES];
[listGradesViewController release];
}
【问题讨论】:
-
vcListGrades 的 course 属性是否声明并定义为retain?
-
您写道:“我经常看到这种格式”,但这不是决定如何编写代码的方式。 Apple 制作了大量优质的文档,也有许多收费或价格合理的优质资源。最后,一个人永远不应该写一行没有确切原因的代码。
-
是的,我将 listGradesViewController 的“课程”定义如下:@property (nonatomic, retain) Course * course;
-
谢谢,伙计们,成功了。与其在调用之前在这里声明“课程”,我需要在我的 .h 中使用保留属性声明它,然后在 .m 中进行综合。我已经从上面更改了我的代码,因此我现在只是引用“课程”变量,而不是声明它。现在似乎可以工作了。
标签: iphone objective-c uinavigationcontroller pushviewcontroller