2013-03-29 11 views
8

Desidero connettere una cella statica con un'azione utilizzando gli storyboard. Il problema è che non è possibile connettere la cella con un'azione, quindi l'ho provata in un altro modo. Così nel mio file di intestazione ho collegato questa proprietà con la cellula statico utilizzando storyboard:Connetti cella statica con un'azione

@property (nonatomic, strong) IBOutlet UITableViewCell *theStaticCell; 

E

UITableViewCell *theCellClicked = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]]; 
if (theCellClicked == _theStaticCell) { 
    NSLog(@"Static cell clicked"); 
} 

Così voglio usare il cellulare "Update", che quando si fa clic il codice sopra viene eseguito.

enter image description here

risposta

14
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (indexPath.section ==1 && indexPath.row == 0) 
    { 
     //Do what you want to do. 
    } 
} 

O

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Cell will be deselected by following line. 
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; 

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    UITableViewCell *staticCell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]]; 

    if (cell == staticCell) 
    { 
     //Do what you want to do. 
    } 
} 
+0

il problema è quando clicco sulla cella, lo sfondo da quella cella diventa blu e questo non scompare, come posso lasciarlo scomparire? –

+1

@nonuma visualizza la risposta modificata. – viral

+0

Come devo farlo se sto usando gli storyboard? –

3

Credo invece di collegare con cella statica si dovrebbe usare TableView delegato Metodo

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
// Put your action logic here by using its index "indexPath.row". 
} 
1
#pragma mark - Table view delegate 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if([tableView cellForRowAtIndexPath:indexPath] == self.theStaticCell){ 
     NSLog(@"Static cell clicked"); 
    } 
}