我有一些在NSMutableArray中的tableView包含類課程UITableView的移動
@interface Lesson : NSObject <NSCoding>{
NSString *time1;
NSString *time2;
NSString *predmet;
NSString *namPrepod;
NSString *zamet;
}
我在tableview中移動排...................... .................................................. .................................................. ......
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
if(segmentedControl.selectedSegmentIndex==0)
{
if(fromIndexPath.section==0)
{
NSMutableArray *r = [[Singleton sharedInstance].chetNedel.monday objectAtIndex:fromIndexPath.row];
[[Singleton sharedInstance].chetNedel.monday removeObjectAtIndex:fromIndexPath.row];
[[Singleton sharedInstance].chetNedel.monday insertObject:r atIndex:toIndexPath.row];
}
if(fromIndexPath.section==1)
{
NSMutableArray *r = [[Singleton sharedInstance].chetNedel.tuesday objectAtIndex:fromIndexPath.row];
[[Singleton sharedInstance].chetNedel.monday removeObjectAtIndex:fromIndexPath.row];
[[Singleton sharedInstance].chetNedel.monday insertObject:r atIndex:toIndexPath.row];
}
,但是當我在程序中移動排我有這個線錯誤
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
..........
if(segmentedControl.selectedSegmentIndex==0)
{
time1 = [[[UILabel alloc] init] autorelease];
time1.font = [UIFont fontWithName:@"Arial-BoldMT" size:13];
time1.tag = tagtime1;
time1.backgroundColor = [UIColor clearColor];
if(indexPath.section ==0)
time1.text =[(Lesson *) [[Singleton sharedInstance].chetNedel.monday objectAtIndex:indexPath.row] time1];
if(indexPath.section ==1)
time1.text =[(Lesson *) [[Singleton sharedInstance].chetNedel.tuesday objectAtIndex:indexPath.row] time1];
if(indexPath.section ==2)
time1.text =[(Lesson *) [[Singleton sharedInstance].chetNedel.wednesday objectAtIndex:indexPath.row] time1];
if(indexPath.section ==3)
time1.text =[(Lesson *) [[Singleton sharedInstance].chetNedel.thirsday objectAtIndex:indexPath.row] time1];
if(indexPath.section ==4)
time1.text =[(Lesson *) [[Singleton sharedInstance].chetNedel.friday objectAtIndex:indexPath.row] time1];
if(indexPath.section ==5)
time1.text =[(Lesson *) [[Singleton sharedInstance].chetNedel.saturday objectAtIndex:indexPath.row] time1];
time1.frame = CGRectMake(8, 12, 300-124, 11);
...........
[cell.contentView addSubview:time1];
我做錯了什麼?
因未捕獲異常'NSInvalidArgumentException'而終止應用程序,原因:' - [__ NSArrayM time1]:無法識別的選擇程序發送到實例0x600c2f0' – Pavel 2012-01-29 11:26:02
此錯誤在此行上 time1.text = [(Lesson *)[[Singleton sharedInstance] .chetNedel .monday objectAtIndex:indexPath.row] time1]; – Pavel 2012-01-29 11:29:11
它的確聽起來像你可能正在訪問一個已經失控的陣列位置。您是否嘗試將removeObjectAtIndex和insertObject:atIndex:合併爲一個exchangeObjectAtIndex:withObjectAtIndex:就像我建議的那樣? – ragamufin 2012-01-29 21:56:34