अपने आवेदन में, मैं tableview से हटाने की पंक्ति के बाद मेरे tableview ([tablView reloadData];
) को फिर से लोड तो canEditRowAtIndexPath
विधि alway (प्रवेशक) कुल पंक्तियों की संख्या के लिए कहते हैं।canEditRowAtIndexPath विधि पर, UITableView का reloadData ठीक से काम नहीं करता है?
उदाहरण के लिए:
मैं अपने tableview पर पंक्तियाँ है, तो मैं पंक्ति tableView से हटा दें। हटाने के बाद, मैं फिर से लोड मेरी tableview ([tablView reloadData]
) लेकिन canEditRowAtIndexPath
विधि कॉल 5 समय बजाय 4 बार ??
Terminating app due to uncaught exception 'NSRangeException', reason: '* **-[__NSArrayM objectAtIndex:]: index 5 beyond bounds [0 .. 4]'
मैं भी कुछ देरी (NSTimer
का प्रयोग करके) के बाद तालिका को फिर से लोड करने की कोशिश की लेकिन यह भी मेरे लिए काम नहीं किया:
तो मैं हमेशा त्रुटि के बाद मिला है।
मैं कुछ कोड यहाँ रखा:
मैं विशेष पंक्ति पर canEditRowAtIndexPath
होता है कि कौन @"status" isEqualToString:@"directory"
इस तरह की तरह,
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%d", self.listOfSounds.count);
// Return NO if you do not want the specified item to be editable.
if([[[self.listOfSounds objectAtIndex:indexPath.row] objectForKey:@"status"] isEqualToString:@"directory"])
return YES;
else
return NO;
}
हटाने पंक्ति के कोड:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[self.sql_ deleteSoundFileAudioTableWhereMainID:[[self.listOfSounds objectAtIndex:indexPath.row] objectForKey:@"main_id"]]; /// delete record from DB
[self.listOfSounds removeObjectAtIndex:indexPath.row]; /// delete record from Array
[self updateListofSoundsFile]; /// Custom method
}
}
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
return NO; // i also tried to return YES;
}
यहाँ updateListofSoundsFile
मेरी है कस्टम विधि कोड है:
-(void)updateListofSoundsFile
{
if(self.listOfSounds.count > 0)
[self.listOfSounds removeAllObjects];
self.listOfSounds = [self.sql_ getAllDataFromAudioTable]; // get all record from DB
NSLog(@"%d",self.listOfSounds.count);
[self.tblView reloadData];
}
कृपया कोई सुझाव दें, मैं इस मुद्दे को कैसे हल कर सकता हूं?
धन्यवाद :)
अपना 'नंबरऑफरोइनससेक्शन' विधि पोस्ट करें। प्रश्न - आपकी 'commit एडिटिंग स्टाइल' विधि में, आप 'updateListOfSoundsFile' क्यों कहते हैं? आप पहले से ही एक ऑब्जेक्ट को हटाकर 'listOfSounds' को अपडेट कर सकते हैं। सरणी से ऑब्जेक्ट को हटाने के बाद, तालिका से एक पंक्ति को हटाने के लिए बस 'DeleteRowsAtIndexPaths' पर कॉल करें।यह भी सत्यापित करें कि 'deleteSoundFileAudioTableWhereMainID' को हटाने के लिए आपका कॉल वास्तव में डेटाबेस से एक पंक्ति को हटा रहा है। – rmaddy