好吧,真的很尷尬地宣佈我把問題都弄錯了。看起來這個對象首先已經超出了範圍。 myObject實際上是[myObjectList objectForIndex:index]其中myObjectList是NSMutableArray * myObjectList。這不是一個綜合財產。目的是從NSObject的派生的類(@interface對象:NSObject的)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
for(Object* p in myObjectList)
{
NSLog(@"%@", p.name); //this returns a garbled message
}
MyObjectDetailViewController * vc = [[MyObjectDetailViewController alloc] initWithStyle:UITableViewStylePlain];
vc.object = [myObjectList objectAtIndex:indexPath.row];
[self.navigationController pushViewController:vc animated:YES]; //when i hover over "vc" in debugger, it shows that vc.object is defined(i see my name variables) but when i hover over myObjectList in the previous line, the objects say "out of scope"
[vc autorelease];
}
要覆蓋所有地面,這裏是陣列被實例化。這個函數是一個來自sqlite的sqlite3_exec的回調函數。
int callback (void* context, int count, char** values, char** columns)
{
NSMutableArray *list = (NSMutableArray*)context;
Object *obj = [[Object alloc] initWithName:[NSString stringWithUTF8String:values[kName]]];
[list addObject:obj];
[obj release];
NSLog(@"After release");
for(Object *p in list)
{
NSLog(@"%@", p.name); //this prints out okay
}
return SQLITE_OK;
}
我希望這會讓問題更清楚一點。 myObjectList超出範圍的事實,但我似乎能夠檢索其對象是真的很奇怪...
此外,爲了澄清,我在這裏使用聲明的屬性,所以在我的aViewController接口中,我有: @property(nonatomic,retain)Object * object; //也sysnthesized – Ying 2010-02-09 17:14:20
什麼類是對象?或者你的意思是NSObject? – 2010-02-09 17:21:25
是myObject被聲明爲保留屬性嗎? – willcodejavaforfood 2010-02-09 18:42:57