私のアプリケーションでは、.plistファイルのセクションを持つテーブルを作成するテーブルビューコントローラがあります。すべてのセルは、plistファイル内のすべての項目に格納され、繰り返すことができないIDパラメータに基づいているため、ユニークです。 PLISTの例として:セルのテキストデータでNSIndexPath(UITableCell用)を取得するにはどうすればよいですか?
<dict>
<key>Section One</key>
<dict>
<key>Item 0</key>
<dict>
<key>name</key>
<string>Some name one</string>
<key>picfile</key>
<string>take8.png</string>
<key>takeItemId</key>
<integer>101</integer>
</dict>
<key>Item 1</key>
<dict>
...
</dict>
</dict>
<key>Section Two</key>
<dict>
<key>Item 0</key>
<dict>
<key>name</key>
<string>Some name two</string>
<key>picfile</key>
<string>take6.png</string>
<key>takeItemId</key>
<integer>103</integer>
</dict>
<key>Item 1</key>....
だから私のテーブルには、テキストラベル(takeItemID)、ファイルから画像や他のテキストラベル(名前)を含む細胞で構成されています。 今、私はIDとして文字列(私はTCPソケット接続からコマンドを受け取る)をもたらすいくつかのイベントがあります。受信したID文字列を対応するテキストラベルとして含むセルで、テーブルをハイライト表示(背景を変更)する必要があります。何とかplistからNSIndexPathを取得することもOKです。
編集:cellForRowAtIndexPath::
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];
NSString *sGroup = [sequencerGroups objectAtIndex:section];
NSDictionary *tSection = [sequencer objectForKey:sGroup];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SecuencerCell"];
NSString *takeItemName = [[[tSection allKeys] sortedArrayUsingSelector:@selector(compare:)] objectAtIndex:row];
NSDictionary *takeItem = [tSection objectForKey:takeItemName];
UILabel *idLabel = (UILabel *)[cell viewWithTag:104];
idLabel.text = [NSString stringWithFormat:@"%@",[takeItem valueForKey:@"takeItemId"]];
UILabel *nameLabel = (UILabel *)[cell viewWithTag:102];
nameLabel.text = [takeItem valueForKey:@"name"];
UIButton *piconButton = (UIButton *)[cell viewWithTag:101];
UIImage *TakeImage = [UIImage imageNamed:[takeItem valueForKey:@"picfile"]];
[piconButton setBackgroundImage:TakeImage forState:UIControlStateNormal];
UIButton *resumeButton = (UIButton *)[cell viewWithTag:103];
UIImage *resumeImage = [UIImage imageNamed:@"resume.png"];
[resumeButton setBackgroundImage:resumeImage forState:UIControlStateNormal];
return cell;
}
編集:ここでは以下の私のtableViewある
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"Sequencer.plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
self.sequencer = dict;
[dict release];
NSArray *array = [sequencer allKeys];
self.sequencerGroups = array;
どうもありがとう、 マキシム
TISがあなたにhttp://borkware.com/quickies/oneを助けるかもしれませんか? topic = UITableView – fibnochi
'tableView:cellForRowAtIndexPath:'のコードを含めることができますか? – dasblinkenlight