开发者

Passing array to parent view controller in navigation-type app

开发者 https://www.devze.com 2023-03-09 16:34 出处:网络
I need to pass an array to my parent view controller, and I\'m not sure how to do that. Is my only choice to use a delegate? My application crashes at the line:

I need to pass an array to my parent view controller, and I'm not sure how to do that. Is my only choice to use a delegate? My application crashes at the line:

[self.parentViewCo开发者_开发百科ntroller setrecipientItems:remoteRecipientItems];

with the message:

[UINavigationController setrecipientItems:]: unrecognized selector sent to instance 0x8a10ab0

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



    int newRow = [indexPath row];
    int oldRow = (lastIndexPath !=nil)?[lastIndexPath row]:-1;

    if (newRow != oldRow) {
        UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
        newCell.accessoryType = UITableViewCellAccessoryCheckmark;

        UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:lastIndexPath];

        oldCell.accessoryType = UITableViewCellAccessoryNone;

        //  lastIndexPath = indexPath;
        lastIndexPath = [indexPath retain];


    }

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    // UIViewController may not respond to setrecipientItems: warning
    [self.parentViewController setrecipientItems:remoteRecipientItems]; 

    [[self.parentViewController.] ]


    [self.navigationController popViewControllerAnimated:YES];


}

Also my parent UIViewController is set up like this:

#import <UIKit/UIKit.h>


@interface AddRecipientsTableViewController : UITableViewController {
NSMutableArray *recipientItems;
}
@property(nonatomic,retain)NSMutableArray *recipientItems;



@end


Your answer is in your question :).

[UINavigationController setrecipientItems:]: unrecognized selector sent to instance 0x8a10ab0

The parent view controller, when using a UINavigationController hierarchy, is UINavigationController, not your previous view controller.

If you want to get at that view controller, ask the UINavigationController for its list of view controllers by calling [self.parentViewController viewControllers], and then you can cycle through that NSArray using isKindOfClass: to determine which one is yours.

An NSNotification could also work in this case, or as you suggest, a delegate.

0

精彩评论

暂无评论...
验证码 换一张
取 消