加载DetailView时的空数据

时间:2013-10-22 22:26:13

标签: objective-c uitableview

我有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;

@end

1 个答案:

答案 0 :(得分:0)

我假设TestDetailView是一个ViewController子类,并且你有一个属性,可能叫datas。如果是这种情况,您似乎在didSelectRowAtIndexPath:中创建了详细视图控制器,如下所示:

TestDetailView *c = [[TestDetailView alloc] init];

然后立即将指针改为其他东西(可能是nil):

c = [_datas objectAtIndex:indexPath.row];

objectAtIndex返回id,这意味着您的代码可能不会在Xcode中发出警告,但在运行时如果[_datas objectAtIndex:indexPath.row]未返回UIViewController(并且我怀疑它没有)你的应用程序可能崩溃。如果它没有抛出错误或崩溃,您可能还有另一个问题,即_datas在父视图控制器中为零。

将值传递给视图控制器是一种非常常见的技术,我建议您阅读如何执行此操作。 S.O.已经提出了这类问题。很多次:

How to set value for NSString in another view controller from one viewcontroller