簡體   English   中英

設置UITableView節時將忽略'If'語句

[英]'If'Statement being ignored when setting UITableView sections

使用多個UITableView定義節的標題時,一直遇到“ if”語句被忽略的問題。 這是在兩個UITableViews上顯示“瑞士”的情況。 下面的代碼-您能解釋什么地方嗎? 我已經嘗試過else ifif ,但都沒有用。

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if ((tableView=_listTableView)) {

        //if(section == 0) {
        return @"Switzerland";
        //}
    }
    else {
       // if(section == 0) {
            return @"A";
}
return 0;

}

干杯,SebOH

if ((tableView=_listTableView))中用==替換=

說明

=是一個賦值運算符,因此_listTableView將被分配給tableView ,並且if條件的評估為if(tableView) ,該條件始終返回true,除非您的_listTableView為null

當您要比較兩個對象時,請使用==而不是一個=:

if ((tableView==_listTableView)) {

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM