editingStyleForRowAtIndexPath doesn't get called

Discussion in 'iOS Programming' started by bluehill, Mar 16, 2011.

  1. bluehill macrumors newbie

    Joined:
    Feb 5, 2011
    #1
    This function gets executed
    Code:
    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPat
    
    but This function is not getting called.... and the minus (-) button doesn't appears
    Code:
    - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

    Code:
    // Implement loadView to create a view hierarchy programmatically, without using a nib.
    - (void)loadView {
    	[super loadView];
    	tblSelectedSupplier = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    	//allocate the view
    	self.view = tblSelectedSupplier;
    	tblSelectedSupplier.delegate = self;
    	tblSelectedSupplier.dataSource = self;
    	
    	//Set the title
    	self.navigationItem.title = @"Selected Supplier";
    	
    	self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStyleBordered target:self action:@selector(save_selSupplier:)]autorelease];
    	
    	[self setEditing:YES animated:YES];
    }
    
    
    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    	NSLog(@"will appear contacts");
        [tblSelectedSupplier reloadData];
    	
    }
    
    -(IBAction)save_selSupplier:(id)sender{
    	
    
    }
    
    
    #pragma mark Table view methods
    
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    	return 1;
    }
    
    // Customize the number of rows in the table view.
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    	return [selectedSuppList count];
    }
    
    - (void)setEditing:(BOOL)editing animated:(BOOL)animated
    {
        [super setEditing:editing animated:animated];
    	NSLog(@"Self edititng");   
    }
    
    //  Update array of displayed objects by inserting/removing objects as necessary.
    //
    - (void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
    {
    	
    	if (editingStyle == UITableViewCellEditingStyleDelete)
        {
    		//  Animate deletion
            NSArray *indexPaths = [NSArray arrayWithObject:indexPath];
            [tblSelectedSupplier deleteRowsAtIndexPaths:indexPaths
    						  withRowAnimation:UITableViewRowAnimationFade];
    		
        }
    	
    
    }
    
    //exclude rows from being edited
    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
    	NSLog(@"table view canEditRowAtIndexPath");
    	return YES;
    }
    
    //editing sytle
    - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    	NSLog(@"Self edititng Insert");
    	return UITableViewCellEditingStyleDelete;
    	
    }
    
    
    // Customize the appearance of table view cells.
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        
    	static NSString *MyIdentifier = @"MyIdentifier";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
    		
    		[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
            UIFont *titleFont = [UIFont fontWithName:@"Helvetica" size:14.0];
            [[cell textLabel] setFont:titleFont];
    	}
    	
    	KeyValue *keyval = [selectedSuppList objectAtIndex:indexPath.row];//[[Dictionary getarrySelSupplier] objectAtIndex:0];
    	//[supplierlist objectAtIndex:indexPath.row];
    	cell.textLabel.text = keyval._value;
    
    	
    	return cell;
    }
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    	NSLog(@"didSelectRowAtIndexPath");
    }
    
    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    	
    	return 45;
    }
    
     
  2. RonC macrumors regular

    Joined:
    Oct 18, 2007
    Location:
    Chicago-area
    #2
    A couple of questions:

    • When do you expect that method to be called?
    • What happens if you swipe right in a cell?
     
  3. bluehill thread starter macrumors newbie

    Joined:
    Feb 5, 2011
    #3
    • When do you expect that method to be called?
      On the view load
    • What happens if you swipe right in a cell?
      The delete button appears

    Thanks its done
    i replaced
    Code:
    [self setEditing:YES animated:YES];
    with this
    Code:
    [tblSelectedSupplier setEditing:YES animated:YES];
    By following code i thought tblSelectedSupplier will act as self, but it doesn't seems so....
    self.view = tblSelectedSupplier;
     

Share This Page