• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Table View with NSMutableArray of objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Table View with NSMutableArray of objects


  • Subject: Table View with NSMutableArray of objects
  • From: luis javier markina <email@hidden>
  • Date: Thu, 18 Oct 2012 10:39:02 +0000
  • Importance: Normal

Hi, I am developing an app and i face this problem. I have a Table view with its view controller and i am trying to fill this table with some data from a NSMutableArray.
I have a class called Lugar.m and Lugar.h, with some properties (with the @synthesize in the .m file) as i show:
@property (nonatomic, strong) NSString *nombre;
@property (nonatomic, strong) NSString *direccion;
@property (nonatomic, strong) NSString *descripcion;
@property (nonatomic, strong) NSString *precio;
Then I have the controller of the table view with the following viewDidLoad method


- (void)viewDidLoad
{
[super viewDidLoad];
self
.title =@"Comer";
Lugar *lugar = [[Lugar alloc] init];
self
.datosTabla = [[NSMutableArray alloc] initWithCapacity:6];
NSArray *nombres = [[NSArray alloc] initWithObjects:@"Masala",@"Italiano",@"Gaia",@"Pekaditos",@"Ojeda",@"Plan B", nil];
NSArray *direcciones = [[NSArray alloc] initWithObjects:@"C/San Roque, 5", @"C/ Moneda, 7 ",@"C/Nueva, 6", @"C/San Roque, 5", @"C/ Moneda, 7 ",@"C/Nueva, 6", nil];
NSArray *descripciones = [[NSArray alloc] initWithObjects:@"Bonito restaurante ecologico",@"Restaurante fino y caro", @"El mejor marisco de burgos",@"Calida recio mud", @"Calidad insuperable" , @"Calidad insuperable",nil];
NSArray *precios = [[NSArray alloc] initWithObjects:@"25€", @"15€", @"12€", @"6€", @"34€", @"34€",nil];
for (NSUInteger i = 0; i < 6; i++) {
lugar
.nombre = [nombres objectAtIndex:i];
lugar
.direccion = [direcciones objectAtIndex:i];
lugar
.descripcion = [descripciones objectAtIndex:i];
lugar
.precio = [precios objectAtIndex:i];
[self.datosTabla insertObject:lugar atIndex:i];
}


In this file i have also the cellForRowAtIndex
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
   
{
       
static NSString *CellIdentifier = @"Cell";
       
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
       
if (cell == nil)
      
{
           cell
= [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
          
Lugar *tempName =[self.datosTabla objectAtIndex:indexPath.row];
           cell
.textLabel.text = tempName.nombre;
      
}
      
return cell;
   
}


I have also the methods that return the rows and the sections
The app runs properly but it shows me just the name of the last object add to the mutableArray, in this case the restaurant called: Plan B. So i have just get a table with 6 rows with the same restaurant information.
I tried to fix it and i spend a lot of hours with no result.

I would thank any help.
Thanks in advance Luis


PD: the information of the arrays is in Spanish
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Table View with NSMutableArray of objects
      • From: Frank Murray <email@hidden>
    • Re: Table View with NSMutableArray of objects
      • From: email@hidden
    • Re: Table View with NSMutableArray of objects
      • From: Robert Martin <email@hidden>
  • Prev by Date: Build Settings and Scriptability
  • Next by Date: Re: Table View with NSMutableArray of objects
  • Previous by thread: Build Settings and Scriptability
  • Next by thread: Re: Table View with NSMutableArray of objects
  • Index(es):
    • Date
    • Thread