• 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
Re: Table View with NSMutableArray of objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Table View with NSMutableArray of objects


  • Subject: Re: Table View with NSMutableArray of objects
  • From: email@hidden
  • Date: Thu, 18 Oct 2012 07:56:00 -0400

On Oct 18, 2012, at 6:39 AM, luis javier markina <email@hidden> wrote:

> 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

In addition to the error Rob pointed out, this needs fixed to. Getting the object and setting its text label needs to be outside the if statement.

 if (cell == nil)
       {
           cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

       }
  Lugar *tempName =[self.datosTabla objectAtIndex:indexPath.row];
  cell.textLabel.text = tempName.nombre;


Dave


 _______________________________________________
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


References: 
 >Table View with NSMutableArray of objects (From: luis javier markina <email@hidden>)

  • Prev by Date: Re: Table View with NSMutableArray of objects
  • Next by Date: Re: Build Settings and Scriptability
  • Previous by thread: Re: Table View with NSMutableArray of objects
  • Next by thread: Re: Table View with NSMutableArray of objects
  • Index(es):
    • Date
    • Thread