2012-11-12 3 views
0

didSelectRowForIndexPath에서 설정할 때 모든 것을 시도하고 UIActivityMonitorView가 회전하지 않습니다. 나는 셀과 그 속성은 디버거에서 초기화하지만 셀 아무것도에 아무것도 수정하려고하면 변경 볼 수 있습니다사용자 정의 테이블 뷰 셀 속성을 수정할 수 없습니다.

CustomCell *cell = (CustomCell *) [tableview cellForRowAtIndexPath];

와 함께 사용자 정의의 tableview 셀을 액세스 할 수 있습니다. performSelectorAfterDelay에서 회전을 시작하는 셀 activityMonitor IBOutlet을 설정합니다. 셀 알파를 0으로 설정하려고해도 아무 일도 일어나지 않습니다.

그러나 IB를 통해 스핀 너를 설정하면 셀이로드 될 때 작동합니다.

또한 태그를 통해 액세스하려고했지만 작동하지 않았습니다.

어떻게 사용자 정의 테이블 뷰 셀에서 속성을 설정합니까?

+0

try [cell setNeedsDisplay]; – Bergasms

답변

1

Table View 프로그래밍 가이드에서 Customizing Cells을 확인하십시오. 그러나 구체적인 내용은 스토리 보드, NIB 또는 프로그래밍 방식으로 생성 된 UITableViewCell 셀에 따라 다릅니다. 진행 상황을 진단하려면 tableView:cellForRowAtIndexPath:tableView:didSelectRowAtIndexPath:을 공유해야합니다. 아래에서는 회전 작동 표시기를 사용하는 예를 보여 드리지만 여기서 특별한 것은 없습니다. 나는 앱에서 계속 진행되는 간단한 일이 있다고 생각하지만, 코드를 볼 수 없다면 우리가 도울 수있는 무언가가 아닙니다.

그러나 Interface Builder에서 정의한 인터페이스를 사용하여 UITableViewCell의 서브 클래스를 만든다고 가정하면 예제를 보여줄 수 있습니다. 다음은 방사 작동 표시기를 시작하는 샘플 didSelectRowAtIndexPath이며 15 초 후 꺼집니다.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    TestCell *cell = (TestCell *)[tableView cellForRowAtIndexPath:indexPath]; 

    // I have a model in my app for the sections of the tableview, as well as the rows, 
    // so let's get the pointer to the appropriate model information. Your implementation 
    // may differ, but hopefully you get the idea. 

    Section *section = self.sections[indexPath.section]; 
    Row *row = section.rows[indexPath.row]; 

    // because we selected this row, start the activity indicator 

    [cell addActivityIndicator]; 

    // let's flag the row in our model to indicate that we're busy here (so if and when 
    // we represent this row, we'll know if we're busy or not) 

    row.loading = YES; 

    // and let's asynchronously dispatch a "stop activity indicator" in 15 seconds 

    int64_t delayInSeconds = 15.0; 
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); 
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ 
     // because this is happening asynchronously, let's re-retrieve the cell 
     // pointer, just in case it might have scrolled off of the visible screen 
     // as is no longer visible or the pointer to the cell might have changed 

     TestCell *currentCell = (TestCell *)[tableView cellForRowAtIndexPath:indexPath]; 

     // let's remove the activity indicator 

     [currentCell removeActivityIndicator]; 

     // let's flag our model to indicate that this row is no longer loading 

     row.loading = NO; 
    }); 
} 

그리고이 시나리오에서

은 나도는 회전 활동 표시를 제시해야하는지 여부를 알아 내기 위해 모델 데이터에서 내 tableView:cellForRowAtIndexPath: 보이는 있는지 확인해야합니다

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"TestCell"; 
    TestCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

    // if I'm using storyboards, the following isn't needed, but if not, I might use something 
    // like the following to load the custom cell from a NIB 

    //if (cell == nil) 
    //{ 
    // NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TestCell" owner:self options:nil]; 
    // cell = (TestCell *)[nib objectAtIndex:0]; 
    //} 

    // this happens to be my model structure, where I have an array of sections, 
    // and each section has its array of Row objects for that section 

    Section *section = self.sections[indexPath.section]; 
    Row *row = section.rows[indexPath.row]; 

    // each "Row" object has two text fields, which I use to update the 
    // two labels in my TestCell subclass of UITableViewCell 

    cell.label1.text = row.text1; 
    cell.label2.text = row.text2; 

    // for this row of this section, figure out whether I need to start animating 
    // the UIActivityIndicator 

    if (row.loading) 
     [cell addActivityIndicator]; 
    else 
     [cell removeActivityIndicator]; 

    return cell; 
} 

그리고 내 여기 UITableViewCell를 서브 클래 싱 작업 표시기를 추가하고 제거하는 코드입니다 :

@interface TestCell() 

@property (strong, nonatomic) UIActivityIndicatorView *activity; 

@end 

@implementation TestCell 

- (void)addActivityIndicator 
{ 
    if (!self.activity) 
    { 
     self.activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
     self.activity.center = self.contentView.center; 
    } 
    [self.contentView addSubview:self.activity]; 
    [self.activity startAnimating]; 
} 

- (void)removeActivityIndicator 
{ 
    if (self.activity) 
    { 
     [self.activity stopAnimating]; 
     [self.activity removeFromSuperview]; 
     self.activity = nil; 
    } 
} 

@end 

이 모든 작동 수있는 방법의 단순한 예이지만, IMPL 효과는 크게 달라질 수 있습니다 (NIB, 스토리 보드, 프로그래밍 방식으로 컨트롤 만들기, 앱 모델의 특성 등). 앱에 위의 코드를 추가하는 것보다는 코드를 우리와 공유하는 것이 더 쉬울 것이며 문제를 아주 빨리 발견 할 수 있기를 바랍니다. 문제는 아마도 간단 할 것입니다.

+0

이 답변을 주셔서 감사합니다. 오늘 밤에 다시 시도해 드리겠습니다. :) – jarryd

관련 문제