現在のアプリケーションに問題があります。 UIViewController
にはUITableView
が1つあります。私は1つUIButton
を(UITableView
の)底部に持っています。それはそのように動作します:私はこの方法でcell.textLabel.text
メソッドを持っていたときサブビューとしてラベルを持つ1つのUITableView内の2 NSArrays?
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"bla"]) {
[[NSUserDefaults standardUserDefaults] setBool:FALSE forKey:@"bla"];
[tableView reloadData];
} else {
[[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:@"tasks2do"];
[tableView reloadData]; }
これは働いていた:私はいくつかの理由のためにそれを必要とするので
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *ident = @"indet";
cell = [tableView dequeueReusableCellWithIdentifier:ident];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:ident] autorelease];
}
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"bla"]) {
cell.textLabel.text = [firstArray objectAtIndex:indexPath.row];
} else {
cell.textLabel.text = [secondArray objectAtIndex:indexPath.row];
}
return cell; }
は、今私は、代わりにcell.textLabel
のUILabel
を使用したいです
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *ident = @"indet";
cell = [tableView dequeueReusableCellWithIdentifier:ident];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:ident] autorelease];
}
UILabel *thislabel = [[[UILabel alloc] initWithFrame:CGRectMake(10, 10, 250, 44)] autorelease];
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"bla"]) {
[thislabel setText:[firstArray objectAtIndex:indexPath.row]];
} else {
[thislabel setText:[secondArray objectAtIndex:indexPath.row]];
}
[cell.contentView addSubview:thislabel];
return cell; }
:そのために
を(。例えば、ラベル枠を設定)私は、次のコードを使用しました
切り替えのためにUIButton
を押すまでは問題ありません。それ、
を(firstArrayとは、文字Lが含まれている、secondArrayは手紙Jが含まれています。それは、セルが新しいテキストを示していますが、新しいテキストはまだあなたがここに見ることができるように古いテキストで後ろに切り替え
私はいくつかのものを試したので、この問題を解決するための考えがありますか(たとえば、アレイに2 UILabel
を使用していますか?クールだろう。 :)
私の英語はあまりにも理解しにくいとは思っていませんが、私の英語力は最善ではありません。残念です。
さらに詳しい情報やコードが必要な場合は、問題ではありません。
お返事ありがとうございます。キャッシュに関する問題を解決したいと思います。それをどうすれば解決できますか? UILabelを動かすと* bla = [[UILabel alloc] init ...]; (セル== nil){ cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:ident] autorelease]; }?さらなる回答ありがとう! – Nicolai
はい、修正する必要がありますが、初期ラベル以外のカスタムラベルへの参照はありません。したがって、このサブクラスを作成することをお勧めします。 –
さて、私はそれをテストしました:それは修正されていない、TableViewは狂っている、スクロール中にテキストが変更されます。サブクラスであなたのやり方についてもっと説明できますか?私は経験豊富ではない。 :( – Nicolai