[英]'If'Statement being ignored when setting UITableView sections
使用多個UITableView
定義節的標題時,一直遇到“ if”語句被忽略的問題。 這是在兩個UITableViews上顯示“瑞士”的情況。 下面的代碼-您能解釋什么地方嗎? 我已經嘗試過else if
和if
,但都沒有用。
- (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.