Я использовал пользовательский вид таблицы ячеек. В каждой ячейке есть текстовое представление и кнопка редактирования. - PullRequest
0 голосов
/ 22 февраля 2012

Я назначил настраиваемое действие для кнопки редактирования.

"Мой запрос - когда я нажимаю кнопку редактирования, он вызывает метод customaction (цель этого метода - редактировать текст в текстовом представлении и сохранять текущие значения вмассив).

Мое требование после повторного редактирования будет возвращено к методу didselctrowatindex. Как я могу вернуться к didselctrowatindex из метода customaction. Вот мой код

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    //The user is selecting the cell which is currently expanded
    //we want to minimize it back

    if(selectedIndex == indexPath.row)
    {
        selectedIndex = -1;

       [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

        return;
    }

    //First we check if a cell is already expanded.

    //If it is we want to minimize make sure it is reloaded to minimize it back
  if(selectedIndex >= 0)
    {

        NSIndexPath *previousPath = [NSIndexPath indexPathForRow:selectedIndex inSection:0];
        selectedIndex = indexPath.row;

        [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:previousPath] withRowAnimation:UITableViewRowAnimationFade];        

    }

    //Finally set the selected index to the new selection and reload it to expand
    selectedIndex = indexPath.row;

    [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

    [button setBackgroundImage:[UIImage imageNamed:@"slider2.png"] forState:UIControlStateNormal]; 

    labelname.textColor = [UIColor yellowColor];

    passionnameslabel.textColor=[UIColor yellowColor];

    textview1.font = [UIFont fontWithName:@"Helvetica" size:15.0f];

    textview1.text = [textview1.text stringByAppendingString:[mylifearray objectAtIndex:indexPath.row]];
    textview1.delegate=self;

    [pes setInteger:selectedIndex forKey:@"selected"];

    [editbutton addTarget:self action:@selector(customActionPressed:)forControlEvents:UIControlEventTouchUpInside];

        [editbutton setBackgroundImage:[UIImage imageNamed:@"edit.png"] forState:UIControlStateNormal]; 
}
-(void)customActionPressed
{



    textview1.inputView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];


    textview1.editable=YES;

     mylifearray=[NSMutableArray arrayWithArray:[pes objectForKey:@"mylifearray"]];

     [mylifearray removeObjectAtIndex:selectedIndex];

     [mylifearray insertObject:textview1.text atIndex:selectedIndex];

         [pes setObject:mylifearray forKey:@"mylifearray"];

}

Может ли любое тело Пожалуйста, помогитеЗаранее спасибо

1 Ответ

0 голосов
/ 22 февраля 2012

Вы можете вызвать метод делегата явно:

[self tableView:self.tableView didDeselectRowAtIndexPath:indexPath];

Или вы также можете написать метод, который выполняет то же действие, что и в didDeselectRowAtIndexPath, и вызывать его как икогда ты нуждаешься.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...