0

I have UITableView I want to click on row and load detail view but I have null information in my Log in detail view would you please help m win this implementation

Thanks in advance!

cellForRowAtIndexPath method:

- (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 method

- (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];

}

but in My detail view

- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:YES];


 NSLog(@" test : %@",_Info.datas);   ==>> my log was (null)

}

My Detail View Header

@property (strong, nonatomic) IBOutlet UILabel *bDetailTitle;
@property (strong, nonatomic) IBOutlet UILabel *bDetailNote;
@property (nonatomic, strong) NSArray *datas;
@property (nonatomic,strong) TestTable *Info;

@end

Ali Mohamad
  • 41
  • 2
  • 10
  • 1
    It looks like you're setting the `TestDetailView c*` to point to one of your data objects directly after allocating it. Which is weird, because that probably should set off a warning. Perhaps you want something like this: `c.datas = [_datas objectAtIndex:indexPath.row];` Without more code, it will be hard to tell. – Aaron Oct 22 '13 at 22:34
  • Also, in `didSelectRowAtIndexPath` can you tell us what `_datas` contains? I'm guessing it contains your data model objects, rather than `UIViewControllers`, but I could be wrong. – Aaron Oct 22 '13 at 22:40
  • @Aaron in _datas is my informtion that i got them from server – Ali Mohamad Oct 22 '13 at 22:44
  • And do you mean to set an object from _datas onto the `TestDetailView` ? – Aaron Oct 22 '13 at 22:45
  • @Aaron I have an error when I set c.datas but I have an error datas is not object of TestDetailView – Ali Mohamad Oct 22 '13 at 22:47
  • @Aaron I just want to load my info from cell to detail view, I have the same label,I don't know what should I add in my didSelectRowAtIndexPath: base on my rows – Ali Mohamad Oct 22 '13 at 22:54
  • Please provide the code in your header file for `TestDetailView`. That way we can see if you have a `datas` property on it, and how it is attributed. – Aaron Oct 22 '13 at 22:55
  • In `viewDidAppear`, what is `_Info` where is that declared? – Aaron Oct 22 '13 at 23:02
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/39777/discussion-between-ali-mohamad-and-aaron) – Ali Mohamad Oct 22 '13 at 23:06

1 Answers1

0

I'm assuming that TestDetailView is a ViewController subclass and that you have a property on it possibly called datas. If that is the case you appear to create your detail view controller in didSelectRowAtIndexPath: like this:

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

But then immediately change it the pointer to something else (possibly nil):

c = [_datas objectAtIndex:indexPath.row];

objectAtIndex returns an id which means your code probably doesn't throw a warning in Xcode, but at run time if [_datas objectAtIndex:indexPath.row] does not return a UIViewController (and I suspect that it does not) your app could crash. If it is not throwing an error or crashing you possibly have another problem in that _datas is nil in your parent view controller.

It is a very common technique to pass values to view controllers I would recommend reading up on how to do this. This type of question has been asked on S.O. many times:

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

Community
  • 1
  • 1
Aaron
  • 7,055
  • 2
  • 38
  • 53