我是Microsoft的长期开发人员,我是使用XCode进行iPhone开发的新手.所以,我正在读一本书,并通过示例尝试自学如何使用Objective-C编写iPhone应用程序.到目前为止一切都很顺利,但偶尔我会objc_exception_throw在运行时遇到通用的' '消息.发生这种情况时,很难找到此异常的来源.经过一些反复试验,我找到了答案.其中一个参数拼写错误.
正如你在下面看到的那样,我错过了'otherButtonTitles'参数,省略了第二个't'按钮.
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Date and Time Selected"
message:message
delegate:nil
cancelButtonTitle:@"Cancel"
otherButonTitles:nil];
Run Code Online (Sandbox Code Playgroud)
这花费我时间的原因是代码构建成功.这是Objective-C编译器的正常行为吗?当我像这样做一个常见的语法错误时,我习惯于在.NET编译器中使构建失败.是否有编译器设置我可以更改以在构建这些错误时使构建失败?
我在tableView中运行以下代码:cellForRowAtIndexPath:
File *file = [[File alloc] init];
file = [self.fileList objectAtIndex:row];
UIImage* theImage = file.fileIconImage;
cell.imageView.image = theImage;
cell.textLabel.text = file.fileName;
cell.detailTextLabel.text = file.fileModificationDate;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
Run Code Online (Sandbox Code Playgroud)
我运行泄漏工具,发现File对象正在泄漏,因为我没有释放它.所以我在返回我认为安全的单元格之前添加了发行版(如下所示):
File *file = [[File alloc] init];
file = [self.fileList objectAtIndex:row];
UIImage* theImage = file.fileIconImage;
cell.imageView.image = theImage;
cell.textLabel.text = file.fileName;
cell.detailTextLabel.text = file.fileModificationDate;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
[file release];
return cell;
Run Code Online (Sandbox Code Playgroud)
现在,当我运行应用程序时,它崩溃了.UITableViewCells仍然引用文件对象吗?在这里使用什么方法来确保我没有泄漏内存?