Note that there are some explanatory texts on larger screens.

plurals
  1. PONSMutableArray to NSString and Passing NSString to Another View IOS5.1
    primarykey
    data
    text
    <p>I have an NSMutableArray of names. I want the pass the data (selected name) inside of NSMutableArray as text to another view's label. </p> <p>FriendsController.m:</p> <pre><code>- (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]; } } </code></pre> <p>In FriendDetail.h</p> <pre><code>NSString nameString; IBOutlet UILabel *profileName; @property (nonatomic, retain) UILabel *profileName; @property (nonatomic, retain) NSString *nameString; </code></pre> <p>In FriendDetail.m</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; profileName.text=nameString; } </code></pre> <p><code>nameString</code> in second controller(FriendDetail) returns <code>nil</code>. When i set a breakpoint in firstcontroller I see the string inside of <code>nameString</code> is correct but after that it returns to <code>nil</code> somehow.</p> <p>-----------------------EDIT----------------------------------------</p> <p>According to answers I have improved my code little bit FriendsController.h</p> <pre><code> FriendDetail *friendController; @property (strong, nonatomic) FriendDetail *friendController; </code></pre> <p>FriendsController.m</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; arrayOfNames=[[NSMutableArray alloc] init]; arrayOfIDs=[[NSMutableArray alloc] init]; arrayOfThumbnails=[[NSMutableArray alloc] init]; userName=[[NSString alloc] init]; friendController= [[FriendDetail alloc] initWithNibName: @"FriendDetail" bundle: nil]; } -(void)request:(FBRequest *)request didLoad:(id)result{ if ([result isKindOfClass:[NSData class]]) { transferImage = [[UIImage alloc] initWithData: result]; friendController.nameString=userName; [friendController view]; friendController.profileImage.image= transferImage; friendController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; [self presentModalViewController:friendController animated:YES]; } //this is how i take facebook friends list if ([result isKindOfClass:[NSDictionary class]]){ items = [[(NSDictionary *)result objectForKey:@"data"]retain]; for (int i=0; i&lt;[items count]; i++) { NSDictionary *friend = [items objectAtIndex:i]; long long fbid = [[friend objectForKey:@"id"]longLongValue]; NSString *name = [friend objectForKey:@"name"]; NSLog(@"id: %lld - Name: %@", fbid, name); [arrayOfNames addObject:[NSString stringWithFormat:@"%@", name]]; [arrayOfIDs addObject:[NSNumber numberWithLongLong:fbid]]; } } } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { long long fbid = [[arrayOfIDs objectAtIndex:indexPath.row]longLongValue]; NSString *user=[NSString stringWithFormat:@"%llu/picture",fbid]; userName=[NSString stringWithFormat:@"%@",[arrayOfNames objectAtIndex:indexPath.row]]; [facebook requestWithGraphPath:user andDelegate:self]; [username retain] } </code></pre> <p>Now when i select row first time it sends name. When i come back to tableview and select another name it shows the old name.</p> <p>If I delete <code>[username retain]</code> in <code>didSelectRowAtIndexPath:</code> it still sends <code>nil</code> to <code>nameString</code></p> <p>when I set break point at <code>didSelectRowAtIndexPath:</code> at line `</p> <pre><code>userName=[NSString stringWithFormat:@"%@",[arrayOfNames objectAtIndex:indexPath.row]]` </code></pre> <p>I can see <code>userName = @"Adam Dart"</code> which is correct </p> <p>in my second breakpoint at line <code>friendController.nameString=userName;</code> I see that <code>nameString =nil</code> and <code>userName = Variable is not CFString</code></p> <p>ARC is set to NO</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload