2015-02-12 1 views

ответ

3

1) В вашем cellForRowAtIndexPath: назначьте кнопку тег как индекс

cell.yourbutton.tag = indexPath.row; 

2) Добавить цель и действие для кнопки, как показано ниже.

[cell.yourbutton addTarget:self action:@selector(yourButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; 

3) Код в действии, основанный на индексе, как показано ниже в ViewControler.

-(void)yourButtonClicked:(UIButton*)sender{ 
[arrayOfTextVaule objectAtIndex:sender.tag];} 

ИЛИ

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
yourCustomCell *selectedCell=[tableView cellForRowAtIndexPath:indexPath]; 
NSLog(@"%@",selectedCell.label);} 
0

Проблема, как я понимаю:

  1. У вас есть пользовательские ячейки с UILabel и UIButton
  2. По щелчку, вы хотите, чтобы название кнопки, чтобы такой же, как на этикетке

Ответ на проблему, как описано выше:

  1. Вам необходимо присвоить метку на метку и кнопки, так что вы можете получить ссылку на них в коде. Для этого:

    1.1. Перейти к описанию доски

    1.2. выберите UILabel

    1.3. из свойств вы можете найти свойство тега, дать ему число (например, 1)

    1.4. Перейдите через 1.1 до 1.3 для UIButton (дайте ему метку номер 2).

  2. в контроллере табличного (файл класса .м), добавьте следующий код:

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
    
        UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath]; // fetch an instance from the cell 
        UILabel * lbl = (UILabel *) [cell viewWithTag: 1]; // fetch an instance of the label 
        UIButton * btn = (UIButton *) [cell viewWithTag: 2]; // fetch an instance of the button 
        btn.title = lbl.text; // I don't remember the text properties :D (figure it our yourself. it should be easy) 
    } 
    
+0

Мне так жаль, что это сработало, я не обновлял свой ответ tnx много – tattiweb

0

Easy ... добавить текст надписи на кнопке accessibilityValue и восстановить его в целевом методе ,

{ 
    UIButton * button = [[UIButton alloc]init]; 
    button.accessibilityValue = label.text; 
    [button addTarget:self action:@selector(sendLabelString:) forControlEvents:UIControlEventTouchUpInside]; 
} 

-(void)sendLabelString:(UIButton*)sender{ 
    NSString * labelString = sender.accessibilityValue; 
}