我有我的TableController的問題。TableViewController - 從數據庫檢索數據
當我打電話的cellForRowAtIndexPath()我能夠從數據庫類檢索信息:
myGroupsAppDelegate *appDelegate = (myGroupsAppDelegate *)[[UIApplication sharedApplication] delegate];
myGroupsDB *mgdb = [ appDelegate.groups_db objectAtIndex:indexPath.row ];
cell.textLabel.text = mgdb.group_name;
[mgdb release];
但如果我嘗試調用從didSelectRowAtIndexPath方法相同()我得到一個錯誤。我需要兩個值傳遞給視圖,我用這個代碼:
SingleGroupView *sgv = [[SingleGroupView alloc] initWithNibName:@"SingleGroupView" bundle:[NSBundle mainBundle]];
myGroupsAppDelegate *appDelegate = (myGroupsAppDelegate *)[[UIApplication sharedApplication] delegate];
myGroupsDB *mgdb = [ appDelegate.groups_db objectAtIndex:indexPath.row ];
sgv.groupID = mgdb.id_group;
sgv.groupName = mgdb.group_name;
[mgdb release];
當我嘗試分配mgdb.id_group到sgv.groupID我得到一個EXC_BAD_ACCESS。看起來mgdb是空的。
-------------- CHANGE ------------------
一個Build後和分析,示出編譯器「對此時沒有所有者的對象的引用計數進行減法「。但是,我在這裏創建,不是本地嗎?所以我加了保留:
myGroupsDB *mgdb = [[ appDelegate.groups_db objectAtIndex:indexPath.row ] retain];
,現在它的工作原理,但是,如果我嘗試調用相同的代碼(只是按下行,更改視圖,再回來,然後按行)沒有日誌應用chrash和用相同的信息。
有什麼建議嗎?
感謝, 安德烈