2013-03-29 13 views
8

Chcę połączyć komórkę statyczną z akcją przy użyciu storyboardów. Problem polega na tym, że nie można połączyć komórki z akcją, więc spróbowałem inaczej. Więc w moim pliku nagłówka Mam podłączony tę właściwość komórek z użyciem statycznego storyboardy:Podłącz komórkę statyczną za pomocą akcji

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

I

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

Więc chcę użyć „Update” komórkę, że po kliknięciu go powyższy kod zostanie wykonany.

enter image description here

Odpowiedz

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

LUB

-(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

Problem polega na tym, że gdy klikam komórkę, tło z tej komórki zmienia się w niebieskie i to nie znika, jak mogę pozwolić, aby to zniknęło? –

+1

@nonuma zobacz edytowaną odpowiedź. – viral

+0

Jak mam to zrobić, jeśli używam scenorysów? –

3

myślę zamiast podłączania go z celi statycznej należy użyć tableview delegata metoda

- (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"); 
    } 
} 
Powiązane problemy