在此先感謝,在我的應用程序中,我試圖用tableviewdidselectrowatindexdex方法顯示第二個視圖控制器。下面是我的代碼,它的工作正常,如果我不使用autorelease,但如果我使用autorelease它給出錯誤,我試過使用NSZombie
啓用發現錯誤,它給這個Autorelease一些錯誤。我在同一個項目的其他類文件中使用了同樣的方法,但是那個時候它正常工作。自動釋放viewcontroller對象創建應用程序崩潰,錯誤爲EXC_BAD_EXCESS
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
CreateMessageViewController *cvc = [[[CreateMessageViewController alloc]initWithNibName:@"CreateMessageViewController"bundle:nil]autorelease];
cvc.Username = [arrayUserName objectAtIndex:indexPath.row];
cvc.UserId = [arrayUserID objectAtIndex:indexPath.row];
cvc.isGroup = @"no";
[self.navigationController pushViewController:cvc animated:YES];
}
else
{
CreateMessageViewController *cvc = [[[CreateMessageViewController alloc]initWithNibName:@"CreateMessageViewControlleriPhone4"bundle:nil]autorelease];
cvc.Username = [arrayUserName objectAtIndex:indexPath.row];
cvc.UserId = [arrayUserID objectAtIndex:indexPath.row];
cvc.isGroup = @"no";
[self.navigationController pushViewController:cvc animated:YES];
}
}
else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
CreateMessageViewController *cvc = [[[CreateMessageViewController alloc]initWithNibName:@"CreateMessageViewControlleriPad"bundle:nil]autorelease];
cvc.Username = [arrayUserName objectAtIndex:indexPath.row];
cvc.UserId = [arrayUserID objectAtIndex:indexPath.row];
cvc.isGroup = @"no";
[self.navigationController pushViewController:cvc animated:YES];
}
}
與我在其他類文件中使用的方法相同,但是不會給出任何錯誤或崩潰,該代碼如下所示。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (StudioManger)
{
NSLog(@"You can edit Schedule");
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
EditScheduleViewController *esvc = [[[EditScheduleViewController alloc]initWithNibName:@"EditScheduleViewController" bundle:Nil]autorelease];
esvc.StudioID = myStudioID ;
esvc.Fromtime = [arrayfromtime objectAtIndex:indexPath.row];
esvc.Totime = [arraytotime objectAtIndex:indexPath.row];
esvc.Date = [arraydate objectAtIndex:indexPath.row];
esvc.Grouptype = [arraygroupname objectAtIndex:indexPath.row];
esvc.DanceType = [arraydancetype objectAtIndex:indexPath.row];
esvc.Day = [arrayDay objectAtIndex:indexPath.row];
esvc.scheduleid = [arrayScheduleID objectAtIndex:indexPath.row];
esvc.StudioName = StudioName ;
[self.navigationController pushViewController:esvc animated:YES];
}
else
{
EditScheduleViewController *esvc = [[[EditScheduleViewController alloc]initWithNibName:@"EditScheduleViewControlleriPhone4" bundle:Nil]autorelease];
esvc.StudioID = myStudioID ;
esvc.Fromtime = [arrayfromtime objectAtIndex:indexPath.row];
esvc.Totime = [arraytotime objectAtIndex:indexPath.row];
esvc.Date = [arraydate objectAtIndex:indexPath.row];
esvc.Grouptype = [arraygroupname objectAtIndex:indexPath.row];
esvc.DanceType = [arraydancetype objectAtIndex:indexPath.row];
esvc.Day = [arrayDay objectAtIndex:indexPath.row];
esvc.scheduleid = [arrayScheduleID objectAtIndex:indexPath.row];
esvc.StudioName = StudioName ;
[self.navigationController pushViewController:esvc animated:YES];
}
}
else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
EditScheduleViewController *esvc = [[[EditScheduleViewController alloc]initWithNibName:@"EditScheduleViewControlleriPad" bundle:Nil]autorelease];
esvc.StudioID = myStudioID ;
esvc.Fromtime = [arrayfromtime objectAtIndex:indexPath.row];
esvc.Totime = [arraytotime objectAtIndex:indexPath.row];
esvc.Date = [arraydate objectAtIndex:indexPath.row];
esvc.Grouptype = [arraygroupname objectAtIndex:indexPath.row];
esvc.DanceType = [arraydancetype objectAtIndex:indexPath.row];
esvc.Day = [arrayDay objectAtIndex:indexPath.row];
esvc.scheduleid = [arrayScheduleID objectAtIndex:indexPath.row];
esvc.StudioName = StudioName ;
[self.navigationController pushViewController:esvc animated:YES];
}
}
else
{
}
}
請幫我一下, 請注意,我沒有使用ARC。而在Xcode 5
錯誤我通過NSZombie獲得工作是如下,
2013年10月28日17:12:34.287舞蹈課程[3855:A0B] * - [AppDelegate的performSelector:withObject: withObject:]:消息發送到釋放實例0xa077590
給你錯誤哪一行代碼? – Kreiri
在CreateMessageMainViewController中按下按鈕後,它會給出確切的結果。後退按鈕的編碼如下 - (IBAction)ClickToBack:(id)發件人 {self.navigationController popViewControllerAnimated:YES]; } – zak
@Kreiri:我編輯了我的問題列出的錯誤,我通過NSZombie啓用。 – zak