【发布时间】:2013-10-23 08:11:59
【问题描述】:
我有 UITableView 我想单击行并加载详细视图,但我的登录详细视图中有空信息 你能帮我赢得这个实施吗
提前致谢!
cellForRowAtIndexPath 方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
//Load Cell for reuse
static NSString *CellIdentifier = @"TestCell";
TestCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell =[ [[NSBundle mainBundle] loadNibNamed:@"TestCell" owner:nil options:nil]
lastObject];
}
_tests = [server info];
_t = [NSMutableString stringWithFormat:@"%@ ", [_tests objectAtIndex:indexPath.row]];
NSString *testdata = _t;
_components = [testdata componentsSeparatedByString:@","];
for (NSString *aComponent in _components) {
if ([aComponent hasPrefix:@"titletest"]) {
_subComponents = [aComponent componentsSeparatedByString:@":"];
_testString = [_subComponents[1] stringByTrimmingCharactersInSet:[NSCharacterSet
characterSetWithCharactersInString:@"\""]];
}if ([aComponent hasPrefix:@"note"]){
_subComponents = [aComponent componentsSeparatedByString:@":"];
_noteString = [_subComponents[1] stringByTrimmingCharactersInSet:[NSCharacterSet
characterSetWithCharactersInString:@"\""]];
break;
}
}
cell.title.text = _testString;
cell.note.text = _noteString;
return cell;
}
didSelectRowAtIndexPath 方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
TestDetailView *c = [[TestDetailView alloc] init];
///I don't know what should I put here to c
[self.navigationController pushViewController:c animated:YES];
}
但在我的详细视图中
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:YES];
NSLog(@" test : %@",_Info.datas); ==>> my log was (null)
}
我的详细视图标题
@property (strong, nonatomic) IBOutlet UILabel *bDetailTitle;
@property (strong, nonatomic) IBOutlet UILabel *bDetailNote;
@property (nonatomic, strong) NSArray *datas;
@property (nonatomic,strong) TestTable *Info;
@结束
【问题讨论】:
-
看起来您正在将
TestDetailView c*设置为在分配后直接指向您的数据对象之一。这很奇怪,因为这可能会引发警告。也许你想要这样的东西:c.datas = [_datas objectAtIndex:indexPath.row];没有更多的代码,很难说。 -
另外,在
didSelectRowAtIndexPath中你能告诉我们_datas包含什么吗?我猜它包含您的数据模型对象,而不是UIViewControllers,但我可能是错的。 -
@Aaron in _datas 是我从服务器获取的信息
-
你的意思是从 _datas 设置一个对象到
TestDetailView上? -
@Aaron 我设置 c.datas 时出错,但我有一个错误 datas is not object of TestDetailView