2017-02-06 5 views
1

У меня есть UIButton внутри a tableviewCell который я загружаю с xib. При нажатии на эту кнопку она должна перейти к следующему представлению ... Я написал перезванивают для этого ..performSegue внутри UIButton callback не работает

Вот мой код в XIb TableViewCell.h

typedef void(^CallBack)(UIButton *sender); 

@property (copy, nonatomic) CallBack callBack; 

TableViewCell.m

- (IBAction)buttonTapped:(id)sender { 
    if (_callBack) { 
    _callBack(sender); 
} 

В ViewController

cell.callBack = ^(UIButton *sender) { 
    [self performSegueWithIdentifier:@"segueIdentifier" sender:nil]; 
}; 

performSegue линия удара номе т его принимать какое-то время, чтобы ударить ... Почему

+1

Вероятно, вам нужно обернуть это в GCD – GeneCode

+0

Нужно ли использовать диспетчер dispatch_async? @GeneCode –

+0

Я думаю, что должен быть только в вашем обратном вызове. заверните только функцию performSegue. – GeneCode

ответ

0

Установка UserInteractionEnabled к NO от пользовательских UIButton и UIView решает мою проблему .. Спасибо за ваш ответ ...

0

Попробуйте это:

@interface WACustomCell : UITableViewCell 

@property(readwrite,copy)void (^cellCallBackMethod)(NSInteger rowIndexPath); 

-(IBAction)buttonTappedFromCell:(id)sender; 

@end 

@implementation WACustomCell 

@synthesize cellCallBackMethod; 

-(IBAction)buttonTappedFromCell:(id)sender{ 

self.cellCallBackMethod(0); 

//any value can be given as we will retrieve this value from CellForRowAtIndex method 

} 

В View Controller

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 

cel = .... 
cell.cellCallBackMethod = ^(NSInteger cellIndex) 

{ 

    [self cellButtonTappedFromCellWithIndex:cellIndex]; 

}; 

return cell; 
} 

-(void)cellButtonTappedFromCellWithIndex:(NSInteger)cellIndex 
{ 

    [self performSegueWithIdentifier:@"segueIdentifier" sender:nil]; 

} 

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 

    if ([[segue identifier]isEqualToString:@"segueIdentifier"]) 

    { 

     ViewController1 *vc = [segue destinationViewController]; 

    } 

} 
+0

вы можете попробовать этот код? –

+0

как это только я сделал, кроме прохождения указательного пути к обратному вызову –

+0

теперь исправлена ​​проблема или нет? –

Смежные вопросы