2012-08-07 108 views
0

我有這個代碼,實際上我想要一個提醒消息,當用戶點擊刪除消息?我怎麼能做到這一點..如何獲取警報消息?

#pragma mark - 
#pragma mark Table Data Source Methods 

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 


    return [list count]; 

} 

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    static NSString *DeleteMeCellIdentifier = @"DeleteMeCellIdentifier"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:DeleteMeCellIdentifier]; 
    if (cell==nil) { 

     cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DeleteMeCellIdentifier]; 
        } 

    NSInteger row = [indexPath row]; 
    cell.textLabel.text = [self.list objectAtIndex:row]; 
    return cell; 

    } 

#pragma mark - 
#pragma mark Table View Data Source Methods 

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 

    NSUInteger row = [indexPath row]; 
    [self.list removeObjectAtIndex:row]; 
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; 


} 

回答

3

請試試這個代碼:

- (void)tableView:(UITableView *)tableView commitEditingStyle: 
(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

if (editingStyle == UITableViewCellEditingStyleDelete){ 
    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Alert" message:[NSString 
    stringWithFormat:@"deleted row no. %@",indexPath.row] delegate:nil 
    cancelButtonTitle:@"Ok" otherButtonTitles: nil]; 
    [alert show]; 
    [alert release]; 
} 
} 
+0

感謝快速回復。它的工作 – developer 2012-08-07 05:50:10

0

你可以試試這個:

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSUInteger row = [indexPath row]; 
    [self.list removeObjectAtIndex:row]; 
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; 

UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Alert" message:[NSString stringWithFormat:@"You have deleted row no. %@",indexPath.row] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil]; 
     [alert show]; 


}