0
votes
 I have two class `first` class and `second` class

I have created 3 section on `tableview` cell for display different value
If I select on section 0 and `indexpath.row` 0 then it push me on `second` class where I have all name list in `tableview` if i select any name then that name should display on first class on section 0  after it happen then i can sent this display value to server please help me on this
what i have to write on second class this method:

when i add this code i get this error -[airport isEqualToString:]: unrecognized selector sent to instance 0x4e54760 2011-09-16 16:44:37.693 RegexKitLiteDemo[36975:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[airport isEqualToString:]: unrecognized selector sent to instance 0x4e54760'

this is my Tfirst.m file



- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"accessory selected");


    if ([indexPath section] == 0)
    {
       // load the appropriate view for the accessory selected
        if ([indexPath row] == 0)
        {
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nameControllerDidSelect:) name:NameControllerDidSelectNotification object:viewtwo];

            viewtwo=[[Originstart alloc]initWithNibName:@"Originstart" bundle:nil];
            [self.navigationController pushViewController:viewtwo animated:YES];
            [viewtwo release];
}
        else{
            NSLog(@"accessory right");
            }

        //[self.navigationController pushViewController:self.approve animated:YES];


    }
}






my Origin.m file

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
    }

    a=(airport*)[app.lstAirports objectAtIndex:indexPath.row];
    NSLog(@"str:%@",a);
    cell.textLabel.text =a.Name;
cell.detailTextLabel.text=a.Code;
    // Configure the cell...

    return cell;
}




#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {



    a.Name = [app.lstAirports objectAtIndex:indexPath.row];

    // Send notification of new selection
    NSDictionary *userDict = [NSDictionary dictionaryWithObject:a.Name  forKey:@"Name"];
    NSLog(@"str:%@",userDict);
    [[NSNotificationCenter defaultCenter] postNotificationName:NameControllerDidSelectNotification object:self userInfo:userDict];
                 }
3
Can you write posts with some syntax?beryllium

3 Answers

1
votes

One way to achieve this is via a notification. Register your higher-level table view controller to receive NameControllerDidSelectNotification (or similar). In the second level table view controller, when tableView:didSelectRowAtIndexPath: is called, add the new selection to a dictionary object and post it in a notification:

#define NameControllerDidSelectNotification    @"NameControllerDidSelectNotification"


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //...

    // Store the selection
    self.name = [self.namesArray objectAtIndex:indexPath.row];

    // Send notification of new selection
    NSDictionary *userDict = [NSDictionary dictionaryWithObject:self.name forKey:@"Name"];
    [[NSNotificationCenter defaultCenter] postNotificationName:NameControllerDidSelectNotification object:self userInfo:userDict];
}

And back in your top-level view controller, first register as an observer of the notification (a good point to do this is when you push the second-level controller), and tell it to fire nameControllerDidSelect::

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nameControllerDidSelect:) name:NameControllerDidSelectNotification object:nextController];

    // ...
    // [self.navigationController pushViewController:nextController animated:YES];
    // ...
}

- (void)nameControllerDidSelect:(NSNotification *)notification
{
    NSDictionary *userDict = [notification userInfo];
    self.selectedName = [userDict objectForKey:@"Name"];

    // Only do this here if your controller automatically pushes back to top-level on selecting a name, else put it in -viewWillAppear
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
1
votes

seems like a case of protocols and delegate .. better read some tutorials on it.... for eg.. http://iosdevelopertips.com/objective-c/the-basics-of-protocols-and-delegates.htmlv

0
votes

I've written you a small example project that demonstrates how to use delegates to pass the information back from a second view controller.

It's rough - but you should get the idea.