2017-01-23 1 views
0

다른 섹션이 포함 된 UITableView가있는 앱이 있습니다. 처음 세 섹션, 즉 색인 경로 0, 1 및 2에만 액세스를 허용하고 싶습니다. 내 문제는 앱이 실행될 때 내 코드가 작동한다는 것입니다. 그러나 테이블 뷰 섹션을 아래로 스크롤하여 테이블 뷰 섹션의 맨 위로 스크롤 할 때 0, 1 및 2는 다시 올 때 사용할 수 없습니다. 이 문제를 어떻게 해결할 수 있습니까?내 tableview를 스크롤 할 때 활성 tableView 셀이 계속 비활성화됩니다.

//formatting the cells that display the sections 
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    let cell = tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell! 

    cell.textLabel?.text = sectionName[indexPath.row] 
    cell.textLabel?.textAlignment = .Center 
    cell.textLabel?.font = UIFont(name: "Avenir", size:30) 

    //Code to block disable every section after row 3. 
    if (indexPath.row >= 2) { 
    cell.userInteractionEnabled = false 
    cell.contentView.alpha = 0.5 
    } 

    return cell 

} 

답변

2

세포가 재사용되고있다. 셀은 재사용되고 성능을 향상시키기 위해 다시 생성되지 않습니다. 따라서 아래로 스크롤하면 상태 확인 때문에 셀의 상호 작용이 사용 중지됩니다. indexPath.row이 2 미만인지 확인해야하는 조건이 없기 때문에 사용자 상호 작용은 재사용 된 셀과 동일하게 유지됩니다 (false).

상태 점검을 조금만 수정하면 문제가 해결됩니다.

if (indexPath.row >= 2) { 
    cell.userInteractionEnabled = false 
    cell.contentView.alpha = 0.5 
} 
else{ 
    cell.userInteractionEnabled = true 
    cell.contentView.alpha = 1 
} 
+0

감사합니다. – pete800

관련 문제