UITableview 單選

摘錄自《iPhone3開發基礎教程》第202頁:

#pragma mark -

#pragma mark Table Delegate Methods

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

{

    int newRow = [indexPath row];

    int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;

    if(newRow != oldRow)

    {

        UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];

        newCell.accessoryType = UITableViewCellAccessoryCheckmark;

        

        UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:lastIndexPath];

        oldCell.accessoryType = UITableViewCellAccessoryNone;

        lastIndexPath = indexPath;

    }

    

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}

發佈了65 篇原創文章 · 獲贊 7 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章