2013-04-22 4 views
0

나는 UITableViewCells의 숫자로 구성된 UITableView을 가지고 있습니다. didSelectRowAtIndex에서 맞춤 UITableViewCell의 속성을 업데이트하는 방법은 무엇입니까?

indexPath.row 2 같으면 테이블 didSelectRowAtIndexPath있어서 발광은, I이 행의 셀 내에 UILabel를 업데이트 할

.

제 생각에는 다음 줄을 따라 뭔가를 사용하는 것이 었습니다. 여기

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
if(indexPath.row == 2){ 

    myCustomCellView *cell = [self.essentialsTableView cellForRowAtIndexPath:indexPath]; 
    cell.myUILabel.text = @"my text"; 

    [tableView reloadData]; 

    } 
} 

문제는 cellForRowAtIndexPath 유형 UITableViewCell하지 myCustomCellView의 객체를 반환합니다.

아무도 내가 didSelectRowAtIndexPath 메서드 내에서 셀의 속성을 액세스하고 업데이트 할 수 있다고 조언 할 수 있습니까?

답변

0

하나의 Bool 값을 "secondRowIsClicked"라고 정의하십시오. viewWillApper 또는 viewDidAppear 기능에서 No로 설정하십시오.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if(indexPath.row == 2) 
    { 
     secondRowIsClicked = YES; 
     [tableView reloadData]; 
    } 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Your code 
    if (secondRowIsClicked == YES) 
    { 
     cell.myUILabel.text = @"my text"; 
    } 
} 
0

를 넣고 코드를 시도 ..

myCustomCellView *cell = (myCustomCellView *) [self.essentialsTableView cellForRowAtIndexPath:indexPath]; 
당신이 우는 소리 같은 그 indexPathUITableViewCell를 다시로드 할 수 있습니다

..

[self.tableView reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone]; 
+0

@Scratcha로 시작하지 않는 당신이 다음 대답을 받아 upvote 대답 유용합니다 :) –

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

myCustomCellView *cell = [self.essentialsTableView cellForRowAtIndexPath:indexPath]; 
UILabel *yourLabel=[cell.contentViews.subviews viewWithTag:indexPath.row+1]; 
//do whatever you want with your label; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Your code 
      cell.myUILabel.text = @"my text"; 
      cell.myUILabel.tag=indexpath.row+1; 
} 
0

은 사용자 정의 셀에 UITableViewCell을 캐스트

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    if(indexPath.row == 2){ 

     myCustomCellView *cell = (myCustomCellView *)[self.essentialsTableView cellForRowAtIndexPath:indexPath]; 
     cell.myUILabel.text = @"my text"; 

     [tableView reloadData]; 

    } 
} 
0

당신은 다시로드에게있는 tableview

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
if(indexPath.row == 2){ 

    //update the array which is used as the data provider in cell for row at index path. 

    [tableView reloadData]; 

    } 
} 
0

myCustomCellViewUITableViewCell의 서브 클래스를 호출 datasoure을 upadte과 서재해야합니다. 그래서 그냥 셀 typcast

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    if(indexPath.row == 2){ 

     myCustomCellView *cell = (myCustomCellView *)[self.essentialsTableView cellForRowAtIndexPath:indexPath]; 
     cell.myUILabel.text = @"my text"; 

     [tableView reloadData]; 

     } 
    } 

상세 정보 : 애플 코딩 가이드 라인에 따라 경찰 사용자 클래스 이름은이 답변이 경우 헤이 소문자 대신 myCustomCellView 사용 MyCustomCellView

관련 문제