I am trying to assign a value to a string variable on a UITableViewController that I push on to my navigationController.
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
// now you can use cell.textLabel.text
NSMutableString *v = [[NSMutableString alloc] init];
[v setString:cell.textLabel.text];
DCAArtistViewController *dvController = [[DCAArtistViewController alloc] init];
if ([v isEqual:@"UK"]) {
dvController.st =@"75";
}
[self.navigationController pushViewController:dvController animated:YES];
I have tried
[dvController.st setString:@"75"];
On the view that is loaded I have an NSLog which always shows null.
NSLog(@"The st is%@",st);
What am I doing wrong? the examples I have seen show assigning to a property on a viewcontroller like this dvController.st =@”75″;
The DCAArtistViewController .h
#import <UIKit/UIKit.h>
@interface DCAArtistViewController : UITableViewController{
NSString *st;
NSMutableArray *aa;
}
@property (nonatomic, retain) NSMutableArray *listOfItemss;
@property (nonatomic, retain) NSString *st;
@property (nonatomic, retain) NSMutableArray *aa;
@end
This is the start of the DCAArtistViewController (The view that is loaded)
@implementation DCAArtistViewController
@synthesize listOfItemss;
@synthesize st;
@synthesize aa;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
aa = [[NSMutableArray alloc] init];
NSLog(@"The st is%@",st);
NSLog(@"The self st is%@",st);
The problem is simple. You are logging
stin yourinitmethod. But you don’t set thestproperty until after theinitmethod is called.