你可以从UITableViewDataSource函数中访问应用

你可以从UITableViewDataSource函数中访问应用

本文介绍了你可以从UITableViewDataSource函数中访问应用程序委托?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出iPhone的SQLite功能,我有一些问题从覆盖的UITableViewDataSource函数读取我的数据库文件。我将数据库文件位置存储在一个ivar(作为NSString)在我的应用程序委托,但是当我尝试从覆盖的UITableViewDataSource函数访问该字符串,它返回一些其他对象。如果我从任何类访问字符串自己的实例方法,它工作正常。

I'm trying to figure out the SQLite functionality for the iPhone, and I'm having some problems reading my database file from an overridden UITableViewDataSource function. I am storing the database file location in an ivar (as an NSString) in my application delegate, however when I try to access that string from an overridden UITableViewDataSource function, it returns some other object. If I access the string from any of the classes own instance methods, it works fine.

有没有办法从覆盖的UITableViewDataSource函数中访问应用程序委托?

Is there any way to access the application delegate from within overridden UITableViewDataSource functions?

推荐答案

问题变得很简单。我创建了NSString保存我的数据库文件的路径使用stringByAppendingPathComponent:。我没有意识到这将是自动释放,所以我没有麻烦明确保留它。这是因为它返回一个不同类型的对象是因为一旦字符串被自动释放后,内存已被重用。

The problem turned out to be really simple. I had created the NSString to hold the path to my database file using stringByAppendingPathComponent: . I failed to realize that this was going to be autoreleased, and so I didn't bother to explicitly retain it. That reason it was returning a different type of object was because that memory had been reused once the string had been autoreleased.

显式保留保存数据库文件路径的字符串解决了这个问题。

Explicitly retaining the string holding the path to the database file solved the problem.

这篇关于你可以从UITableViewDataSource函数中访问应用程序委托?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 01:51