سؤال

I have a ViewController that has a TableView and I want to Get the value from the didSelectRowAtIndexPath so i can pass to another view.

This is the Method:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{   
    // That's the string that I want to get the value
    NSString *selectRow = [_vinhoArray objectAtIndex:indexPath.row];
    stringTest = selectRow;
}

I create and synthesize the property stringTest

@property (nonatomic, strong) NSString *stringTest;
@synthesize stringTest;

to assign the value from selectRow but i guess that i'm doing something wrong. Because this doesnt work.

Anybody can help me? Thanks

هل كانت مفيدة؟

المحلول

First, I would try to just see if you are assigning a value by nslog

NSLog(@"%@", [_vinhoArray objectAtIndex:indexPath.row]);

Then if you are getting something in the log, you can try

self.stringTest = [_vinhoArray objectAtIndex:indexPath.row];

if you are storing NSStrings in your array.

Try this,

create your string in AppDelegate.h

@property (nonatomic, retain) NSString *myTitleString;

Now anywhere you want to access this string, you are going to need to include the appDelegate at the top

#import "AppDelegate.h"

and then use this to access it

AppDelegate *AppDelegate = [[UIApplication sharedApplication] delegate];

assign it with

AppDelegate.MyTitleString = //whatever you are going to assign it with;

in your other view controller you will do the same thing, import the appdelegat.h at the top, create the app delegate and give it's value to your title

NSString *MyStringInTheDifferentController = AppDelegate.MyTitleString;

نصائح أخرى

Insert the following method right after @synthesize stringTest;:

- (void)setStringTest:(NSString *)stringTest
{
    _stringTest = stringTest; // Insert a breakpoint here
    /* You should see here what value does stringTest have and also who called this setter. */
}

I think that this is the best way to debug because you may override the stringTest property right after tableView:didSelectRowAtIndexPath and you may not know it.

P.S.: If you don't use ARC that setter needs to be updated.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top