[英]Tableview with 2 section
您好我正在開發一個使用帶有兩個部分的tableview(而不是單選按鈕)的應用程序。 所以我希望這些部分像單選按鈕一樣。 為了實現這一點,我必須在- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
實現“if” - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
我想使用類似的東西:if(section ==“A”)。 怎么做? 這也是使表格的各個部分表現得像不同表格的正確方法嗎?
我不知道你的意思是“部分像單選按鈕一樣”但要區分tableView:didSelectRowAtIndexPath:
部分tableView:didSelectRowAtIndexPath:
使用indexPath.section
:
if (indexPath.section == 0) {
// first section
} else if (indexPath.section == 1) {
// second section
}
嗯......這聽起來像是一個奇怪的設置,但indexPath
,你只需使用提供的indexPath
來獲取部分/行。
即: indexPath.section
將指向所選的部分, indexPath.row
將指向該行。
有關更多信息, iOS表格視圖編程指南是一個良好的開端,因為它涵蓋了上述所有細節。
UPDATE
在突出顯示多個單元格方面,我認為您需要創建自己的突出顯示概念,當用戶選擇單元格時,您可以打開和關閉它。
也就是說,您也可以根據現有的UITableViewCellAccessoryCheckmark
標記所選單元格是否可以配置UITableView以允許多項選擇? 問題/答案。
您必須使用indexPath.section:
來區分您的表部分
所以你的代碼應該如下所示。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
{
if (indexPath.section == 0)
{
//first section
}
else if (indexPath.section == 1)
{
//second section
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.