NSMutableArray to NSString and Passing NSString to Another View IOS5.1

Posted by Space Dust on Stack Overflow See other posts from Stack Overflow or by Space Dust
Published on 2012-06-25T02:50:28Z Indexed on 2012/06/25 3:16 UTC
Read the original article Hit count: 457

I have an NSMutableArray of names. I want the pass the data (selected name) inside of NSMutableArray as text to another view's label.

FriendsController.m:

- (void)viewDidLoad {
    [super viewDidLoad];
    arrayOfNames=[[NSMutableArray alloc] init];
    arrayOfIDs=[[NSMutableArray alloc] init];
    userName=[[NSString alloc] init];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    long long fbid = [[arrayOfIDs objectAtIndex:indexPath.row]longLongValue];
    NSString *user=[NSString stringWithFormat:@"%llu/picture",fbid];
    [facebook requestWithGraphPath:user andDelegate:self];

    userName=[NSString stringWithFormat:@"%@",[arrayOfNames objectAtIndex:indexPath.row]];
    FriendDetail *profileDetailName = [[FriendDetail alloc] initWithNibName: @"FriendDetail" bundle: nil];

    profileDetailName.nameString=userName;

    [profileDetailName release];
}

- (void)request:(FBRequest *)request didLoad:(id)result  {
    if ([result isKindOfClass:[NSData class]]) {
        transferImage = [[UIImage alloc] initWithData: result];
        FriendDetail *profileDetailPicture = [[FriendDetail alloc] initWithNibName: @"FriendDetail" bundle: nil];

        [profileDetailPicture view];
        profileDetailPicture.profileImage.image= transferImage;

        profileDetailPicture.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        [self presentModalViewController:profileDetailPicture animated:YES];

        [profileDetailPicture release];
    }   
} 

In FriendDetail.h

NSString nameString;
IBOutlet UILabel *profileName;
@property (nonatomic, retain) UILabel *profileName;
@property (nonatomic, retain) NSString *nameString;

In FriendDetail.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    profileName.text=nameString;
}

nameString in second controller(FriendDetail) returns nil. When i set a breakpoint in firstcontroller I see the string inside of nameString is correct but after that it returns to nil somehow.

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about ios