Hi guys!
I am trying to get back a value that I put in an array of structs wrapping these structs using NSValue.
I have these on my myAppDelegate.h :
Code:
typedef struct {
NSInteger ticketId;
NSString *eventTitle;
NSString *eventInfo;
} TicketDataStruct;
@interface myAppDelegate : NSObject <UIApplicationDelegate> {
[...]
NSMutableArray *dataArray;
[...]
}
[...]
@property (nonatomic, retain) NSMutableArray *dataArray;
[...]
then, in myAppDelegate.m:
Code:
@synthesize dataArray;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
TicketDataStruct str;
str.ticketId = 543;
str.eventTitle = @"My event";
str.eventInfo = @"My event info";
NSValue *myValue = [NSValue value:&str withObjCType:@encode(TicketDataStruct)];
dataArray = [[NSMutableArray alloc] initWithObjects:nil];
[dataArray addObject:miValor];
[...]
}
Now, How can I get access to the values of the structs?
I am trying with this, but I am getting nil (This code is inside (UITableViewCell *)tableView

UITableView *)tableView cellForRowAtIndexPath

NSIndexPath *)indexPath):
Code:
[...]
myAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
TicketDataStruct retVal;
NSValue *t = [[NSValue alloc] initWithBytes:[delegate.dataArray objectAtIndex:indexPath.row] objCType:@encode(TicketDataStruct)];
[t getValue:&retVal];
topLabel.text = [[NSString alloc] initWithString:retVal.eventTitle];
[...]
But it doesn't work. I am getting nil in retVal.eventTitle.
Can you help me?
Thanks!