1

最新の SDK と XCode 4.5.2 を使用して iPhone アプリケーションを開発しています。

ViewController には 2 つありUITableViewます。どちらも同じものを使用しUITableViewDataSourceます。私の質問は についてstatic NSString* CellIdentifier;です。

次のことはできますか?

- (UITableViewCell* )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString* CellIdentifier;
    SingletonGlobalVars* singleton = [SingletonGlobalVars sharedInstance];

    if ([tableView isEqual:shopsList])
    {
        CellIdentifier = @"ShopCell";
    }
    else
    {
        CellIdentifier = @"ProductCell";
    }

   [ ... ]
}

変更する必要がありますが、静的変数CellIdentifierでこれを行うことができるかどうかわかりません。

4

2 に答える 2

1

コードは機能しますが、静的変数を使用しても意味がありません。ローカル変数を使用するだけです。また、ポインターを直接比較できることにも注意してください。ここでUITableView使用する必要はありませんisEqual

NSString* cellIdentifier;
if (tableView == shopsList)
{
   cellIdentifier = @"ShopCell";
}
else
{
   cellIdentifier = @"ProductCell";
}

(これshopsListはテーブル ビューの 1 つだと思います。)

于 2013-01-19T11:53:57.840 に答える
-1

静的変数に値を割り当てることができるのは1回だけです。

この場合、次のように2つの異なるCellIdentifiersを使用できます。

static NSString* CellIdentifierShop = @"ShopCell";
static NSString* CellIdentifierProduct = @"ProductCell";

それがうまくいくかどうか私に知らせてください:)

于 2013-01-19T11:46:35.793 に答える