ビューコントローラーを備えたテーブルビューがあり、このテーブルに NSMutableArray からのデータを入力しようとしています。
私が示すように、いくつかのプロパティ(.mファイルに@synthesizeを含む)を持つLugar.mおよびLugar.hというクラスがあります。
@property (nonatomic, strong) NSString *nombre;
@property (nonatomic, strong) NSString *direccion;
@property (nonatomic, strong) NSString *descripcion;
@property (nonatomic, strong) NSString *precio;
次に、次のviewDidLoadメソッドを使用してテーブルビューのコントローラーを持っています
- (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];
}
このファイルには 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;
}
行とセクションを返すメソッドもあります
アプリは正常に実行されますが、mutableArray に追加された最後のオブジェクトの名前だけが表示されます。この場合、レストランは Plan B と呼ばれます。同じレストラン情報を持つ 6 行のテーブルを取得しました。
私はそれを修正しようとしましたが、結果が得られずに何時間も費やしました。どんな助けにも感謝します。前もってありがとうルイス
PD: アレイの情報はスペイン語です。申し訳ありません