我有来自后端的一些数据的 UITableView,我在表中拥有所有内容,3 UILable,我将从后端获取该信息,我可以在表行中显示它们,当我单击行时,我希望在我的详细信息视图中具有相同的标签,但是现在,我的所有详细视图中只有一个信息,相同的信息,只需加载所有详细视图的最后一行,
请您在此实施中帮助我,在此先感谢!
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;
}