[英]EXC_BAD_ACCESS error on starting application
我這里有奇怪的東西。 我有UITableViewController以及協議中所有必需的方法,以及將在其中使用的數據。 然后我有這段代碼(簡體)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSDictionary* cellData = [self.tableViewData objectAtIndex:indexPath.row];
// the rest of the code
return cell;
}
只需單擊幾次即可執行此TableViewController,因此不會在AppDelegate或開始加載的ViewController中的任何位置調用或引用此TableViewController。 但是,當我構建(成功)並在模擬器中運行應用程序時,在顯示任何內容之前,它會退出並顯示EXC_BAD_ACCESS錯誤。 我發現當我注釋行時:
NSDictionary* cellData = [self.tableViewData objectAtIndex:indexPath.row];
一切正常。 為什么這有什么呢? 另外,tableViewData已加載到viewDidLoad中,並且在此行之前未釋放,其他一切正常(我什至可以刪除此行以下的行)。 無論如何,它甚至不應該發送此錯誤,但是它確實可以並且在應用程序啟動時完成。 是什么賦予了?
編輯:這是viewDidLoad方法:
- (void)viewDidLoad {
[super viewDidLoad];
self.tableViewData = [self getABContactsWithMail]; //gets filtered contacts from addressbook, works fine
}
這是代碼的其他部分:
- (void)viewDidUnload {
[super viewDidUnload];
self.tableViewData = nil;
}
-(void)dealloc{
[tableViewData release];
[super dealloc];
}
編輯:這是我從tableView:cellForRowAtIndexPath中的po tableViewData得到的:
<__NSArrayM 0xfdcfe30>(
{
email = "test@test.com";
firstName = test;
fullName = "test account";
id = 1;
lastName = account;
phone = "1 (231) 23";
},
{
email = "gmail@email.com";
firstName = nolast;
fullName = nolast;
id = 3;
lastName = "";
phone = "";
},
{
email = "asdkjf@sdfklja.com";
firstName = "";
fullName = nofirst;
id = 4;
lastName = nofirst;
phone = "";
},
{
email = "test@adsfk.com";
firstName = "";
fullName = "aaa.test@adsfk.com";
id = 5;
lastName = "";
phone = "";
}
)
編輯:我添加了方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
並且我得到了與偽數據相同的行為。 似乎UITableViewController本身有問題或我的xcode搞砸了...
您能否提供給我們您的方法-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)部分
應該看起來像這樣:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [tableViewData count];
}
我終於通過反復試驗找到了它。 顯然,我的UITableViewController實現了一些已經在其父類中實現的協議。 這就是整個問題...
我真的不知道為什么整個應用程序都在無關緊要的地方被錯誤的錯誤壓縮了。 如果這是我的編碼錯誤,則編譯器至少應警告我。
我也記得在Xcode 3上我這樣做沒有問題...
我將此錯誤提交給Apple ...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.