tableview delete error with touch interface after tableView:commitEditingStyle:forRowAtIndexPath: has been used
I am overriding tableView:commitEditingStyle:forRowAtIndexPath to become a method that resets the textlabels in my uitableviewcells however this seams to be causing errors when the user next touches the uitableview.. it has to be touched once before itll do anything (so it takes two touches to actually get any response.)
Im hoping someone can help who has also been in a similar situation;. My code is below.. I have debuged it down to the tableView:commitEditingStyle:forRowAtIndexPath method as if I comment out tableview:titleForDeleteConfirmationButtonForRowAtIndexPath: method the same thing still happens.. So i think i am doing something wrong by overriding the other method.
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
return @"Clear";
}
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
//[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
//reset uitableviewcell textlabel with default input "empty"
vehicleSearchObjectString = @"empty";
[self.tableView reloadData]; //reloads the tabels so you can see the value.
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
UPDATE This is where I set my uitableviewcell textlabel
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"VehicleSearchCell" owner:self options:nil];
cell = vehicleSearchCell;
self.vehicleSearchCell = nil;
}
// Configure the cell...
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if(indexPath.section == 0)
{
if(indexPath.row == 0)
{
UILabel *label1;
开发者_运维百科label1 = (UILabel *)[cell viewWithTag:1];
label1.text = @"Manufacture";
UILabel *label2;
label2 = (UILabel *)[cell viewWithTag:2];
label2.text = vehicleSearchObjectString;
}
//...
If you're in this method, you've enabled editing on the table, I suggesting checking where/when it is disabled, as this could be the cause for a click looking like ignored.
Another lead I would follow is to avoid the reloadData method which fires quite a lot of things and sometimes not controllable by the developer. You've got the indexPath so you can target the single cell for updating by using :
- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath
on the table view.
Last thing I would investigate is Apple's comment on updating tables : http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/TableView_iPhone/ManageInsertDeleteRow/ManageInsertDeleteRow.html#//apple_ref/doc/uid/TP40007451-CH10-SW1 It says that the commit... method must call the method :
deleteRowsAtIndexPaths:withRowAnimation:
or similar for insert, but it doesn't what happens if not.
So I have solved the problem!... I basically deleted the views .h.m.xib started again pretty much copied my code right across to the file and it works perfectly... I have no idea why this happened maybe something I did when I very first set it up.. I'm not sure...
精彩评论