0

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

@结尾

4

1 回答 1

0

我假设这TestDetailView是一个 ViewController 子类,并且你有一个属性可能叫做datas. 如果是这种情况,您似乎会didSelectRowAtIndexPath:像这样创建详细视图控制器:

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

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

c = [_datas objectAtIndex:indexPath.row];

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

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

如何从一个视图控制器为另一个视图控制器中的 NSString 设置值

于 2013-10-22T23:01:05.487 回答