i have defined variable in GroupView.h
@interface GroupView()
{
NSMutableArray *chatrooms;
}
@end
@implementation GroupView
Now i want to pass this variable in segue
@interface FriendsViewController ()
@end
@implementation FriendsViewController
else if ([segue.identifier isEqualToString:@"showGroupView"]) {
GroupView *groupView = (GroupView *)segue.destinationViewController;
groupView.chatrooms = [NSMutableArray arrayWithArray:chatrooms];
}
i know that chatrooms has to be property in header file to code this way but it is not
So is there any way to use this variable in segue.
Thanks for help.
chatrooms
defined as an ivar like you have done is accessed using ->
notation:
groupView->chatrooms = [NSMutableArray arrayWithArray:chatrooms]
This is generally discouraged, though. You should use a property instead:
@interface GroupView
@property (strong) NSMutableArray *chatrooms;
@end
Incidentally, if you're using an NSMutableArray
, that indicates that you want to modify the element list of the array directly and not just replace the array wholesale. If you only ever want to replace the array with a whole new array every time, I suggest using NSArray
instead.
Another point to make here is that you're attempting to cast the object held at segue.destinationViewController
as a GroupView
. You have either named a UIViewController
subclass in a very misleading way, or you are not accessing the GroupView
as a correct member of the UIViewController
that is returned to you.