バックエンドからのデータを含むUITableViewがあり、すべてがテーブルにあり、3 UILableであり、バックエンドからその情報を取得し、それらをテーブル行に表示できます。行をクリックすると、詳細ビューに同じラベルが必要です、しかし今、すべての詳細ビューに同じ情報が 1 つだけあり、すべての詳細ビューの最後の行をロードするだけです。
この実装で私を助けてください、事前に感謝します!
cellForRowAtIndexPath メソッド
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
static NSString *CellIdentifier = @"BooksCell";
BooksCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell =[ [[NSBundle mainBundle] loadNibNamed:@"BooksCell" owner:nil options:nil]
lastObject];
}
_books = [server get_tests:10 offset:0 sort_by:0 search_for:@""];
_t = [NSMutableString stringWithFormat:@"%@ ", [_books objectAtIndex:indexPath.row]];
NSString *testdata = _t;
_components = [testdata componentsSeparatedByString:@","];
NSLog(@"_components: %@",_components);
for (NSString *aComponent in _components) {
if ([aComponent hasPrefix:@"title"]) {
_subComponents = [aComponent componentsSeparatedByString:@":"];
_titleString = [_subComponents[1] stringByTrimmingCharactersInSet:[NSCharacterSet
characterSetWithCharactersInString:@"\""]];
}if ([aComponent hasPrefix:@"authors"]){
_subComponents = [aComponent componentsSeparatedByString:@":"];
_writerString = [_subComponents[1] stringByTrimmingCharactersInSet:[NSCharacterSet
characterSetWithCharactersInString:@"\""]];
}if ([aComponent hasPrefix:@"name"]){
_subComponents = [aComponent componentsSeparatedByString:@":"];
_publisherString = [_subComponents[1] stringByTrimmingCharactersInSet:
[NSCharacterSet characterSetWithCharactersInString:@"\""]];
break;
}
}
cell.bookTitle.text = _titleString;
cell.writer.text = _writerString;
cell.publisher.text = _publisherString;
return cell;
}
didSelectRowAtIndexPath メソッド
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
BooksDetailView *c = [[BooksDetailView alloc] init];
[self.booksTable addSubview:c.view];
c.bDetailTitle.text = _titleString;
c.bDetailWriter.text = _writerString;
c.bDetailPublisher.text = _publisherString;
}