0

私は非常にトリッキーな状況にあります。そして、私がプログラムで行ったすべてのこと。

1) UITableView があります。
2) このテーブルビューのすべてのセルに、1 つの uibutton があります。
3) [はい] ボタンと [いいえ] ボタンがUIButtonある を表示したい をクリックすると。4) [はい] ボタンをクリックすると、このアラートビューが表示された セルを削除したいと思います。UIAlertView
UIButton

以下は私のコードスニペットです:

- (void) removeFriends:(id)sender
{
    /* 
     I want to show alertview at here...

     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"CONFIRM",nil) message:NSLocalizedString(@"REMOVE_FRIEND",nil)  delegate:self cancelButtonTitle:@"No"  otherButtonTitles:@"Yes", nil];

     alert.tag = 21;

     alert.accessibilityIdentifier = @"Remove";

     [alert show];

     */

    UIButton *btn = (UIButton*)sender;

    int indx = btn.tag;
    NSString *friend_id = [friendsId valueForKey:[NSString stringWithFormat:@"%d",indx]];

    // URL creation
    NSString *path = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"path"];

    NSString *address = [NSString stringWithFormat:@"%@%@%@", path,@"users/",usrId];

    NSURL *URL = [NSURL URLWithString:address];

    // request creation
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL cachePolicy:NSURLCacheStorageAllowedInMemoryOnly
                                                       timeoutInterval:60.0];
    [request setHTTPMethod:@"DELETE"];

    responseData = [[NSMutableData alloc] init];

    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    [connection start];

    UITableViewCell *buttonCell = (UITableViewCell *)[btn superview];
    NSIndexPath* pathOfTheCell = [self.table indexPathForCell:buttonCell];

    [self.table deleteRowsAtIndexPaths:[NSArray arrayWithObjects:pathOfTheCell, nil] withRowAnimation:UITableViewRowAnimationFade];
    [self viewDidLoad];
    [self.table reloadData];
}

-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if([alertView.accessibilityIdentifier isEqualToString:@"Remove"])
    {
        if (buttonIndex == 1)
        {
            // here want to make call to  server
        }
    }
}
4

4 に答える 4

0
-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if([alertView.accessibilityIdentifier isEqualToString:@"Remove"])
{
    if (buttonIndex == 1)
    {
        // add server call to delete the relevant data
        // and then refresh your array that you are using in cellForRowAtIndex
        //and reload table. thats it.
    }
}
于 2013-09-04T13:37:59.897 に答える
0

view.h

@interface MyReservationViewController : UIViewController
{
    int Delete_row;
}

ビュー.m

- (IBAction)delete_btn:(id)sender
{
    UIButton *buttontag = (UIButton *)sender;
    //NSLog(@"%d",buttontag.tag);
    Delete_row = buttontag.tag;

    UIAlertView *Alert = [[UIAlertView alloc]initWithTitle:@"Delete Reservation"   message:@"Are you sure to want Delete Reservation ??" delegate:self cancelButtonTitle:@"Delete" otherButtonTitles:@"Cancel",nil];
    Alert.tag=1;
    [Alert show];
    [Alert release];
}


-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{
    if(alertView.tag==1)
    {
        if(buttonIndex == 0)
        {
            NSLog(@"%d",Delete_row);
            //delete cell

            [Arr removeObject:Delete_row];
            [tbl reloadData];

        }
    }
}
于 2013-09-04T13:01:29.973 に答える