Reputation: 19418
I am having trouble in accessing an array within a structure. How can I access an array which is stored in a structure ? I have a structure, say,
@interface FoodDriveRow : NSObject
{
NSMutableArray *teamData;
}
@property (nonatomic , retain) NSMutableArray *teamData;
@end
FoodDriveRow *row ;
now I want to access the array.
Edit
@interface TeamRow : NSObject
{
NSString *membername;
NSString *email;
NSString *phone;
}
@property (nonatomic , retain) NSString *membername;
@property (nonatomic , retain) NSString *email;
@property (nonatomic , retain) NSString *phone;
@end
I am trying to store an object of TeamRow in to the array by
[row.teamData insertObject:tRow atIndex:tIndex1];
and want get the values from the array.
Thanks...
Upvotes: 0
Views: 148
Reputation: 4276
You need to allocate the array, at the moment your array has a nil
value.
Impliment -(id)init
Then within that you want to allocate your array and add some objects to it:
teamData = [[NSMutableArray alloc] init];
TeamRow *teamRow = [[TeamRow alloc] init];
[teamData addObject:teamRow];
[teamRow release];
Now you can access objects:
TeamRow *retrievedTeamRow = [teamData objectAtIndex:0];
Upvotes: 4
Reputation: 31730
FoodDriveRow* myDriveRow;
Use it as below , lets suppose you store NSString object in array
For Adding
- (void)addObject:(id)anObject
[myDriveRow.teamData addObject:myString];
For Removing
(void)removeObject:(id)anObject
For Accessing
- (id)objectAtIndex:(NSUInteger)index
Upvotes: 3
Reputation: 12979
This isn't a structure (struct
) that you are referring to, it's a class
called FoodDriveRow
that descends directly from NSObject
. In order to access properties from an object, you can use the old style:
[[row teamData] objectAtIndex:i]
Or you can use the new dot syntax:
[row.teamData objectAtIndex:i]
Upvotes: 1
Reputation: 581
Did you try [row.teamData objectAtIndex:0]
or from within the class itself, [self.teamData objectAtIndex:0]
?
Upvotes: 2
Reputation: 7982
[[row teamData] objectAtIndex: i];
where i is the index in the array.
Upvotes: 1
Reputation: 26400
I am not sure I understand you but I think you can do this by row.teamData
Upvotes: 1