tableViewのtitleForHeaderInセクションで複合文字列を返そうとすると、奇妙な問題が発生します。UITableView titleForHeaderInSectionが正しいstringWithFormatを返しません
文字列をNSLogすれば良いと思われますが、返すとクラッシュします!
はここに私のコードです: "5" による
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
NSString *title = NSLocalizedString(@"favorites",@"");
NSLog(@"%@", title); // this prints the correct title ("Items" for example...)
int number = (*_tabsections_especes)[0][0];
NSLog(@"%d", number); // this prints the correct number ("5", for example...)
NSLog(@"%@", [NSString stringWithFormat:@"%@ : %d", title, number ]);
// this prints the correct concatenated string ("Items : 5", for example);
return [NSString stringWithFormat:@"%@ : %d)", title, number ];
// --> this either crashes the app, or returns anything in the title,
// for example the title of a resource image or another pointer...
}
私が交換した場合、 "[0] [0](* _tabsections_especes)"、例えば、問題が解消されません。 したがって、問題はstringWithFormatメソッドでNSLocalizedStringを使用し、それを返すことです。
私は間違っていますか?
あなたの戻り値のようなサウンドは、テーブルビューでアクセスできるようになる前にリリースされています。 NSLocalizedStringを使わずにタイトルを直接設定しようとしましたか? –
はい、実際は悪化しています! 'return @ NSString stringWithFormat:@"%@(%d) "、@" titre "、5];'を書くと、アプリがクラッシュします。私は本当に何が起こっているのか分からないのですか?このコードはまだ非常に簡単ですか? – Chrysotribax
OK、キースおよびフィブノキー。 – Chrysotribax