Xcode – Rovnaky cell ale iny obsah

Domov Diskusné Fóra Pomoc: software Xcode – Rovnaky cell ale iny obsah

Zobrazuje sa 7 príspevkov - 1 až 7 (z celkového počtu 7 )
  • Autor
    Príspevky
  • #99909
    PATFFO
    Účastník (Participant)

    Zdravím,
    som začiatočnik v xcode tak sa hrajem no a mam menší problem.
    Skusam robit aplikaciu kde si zistis kedy ti pôjde bus. Vyberes si zastavku, spoj a vybehnu ti časy.
    Ja to mam zrobene tak že :

    if ([_cas isEqualToString:@“4 – Sídlisko III“]) {
    cell.textLabel.text = [dvaOBR objectAtIndex:indexPath.row];

    lenže tento autobus ide aj cez ine zastavky tak mi vypisuje ten isty text (resp. časy) ale ja chcem rozdielne ako to mam urobiť?

    #381590
    mayoxy
    Účastník (Participant)

    musis si spravit nejake pole.. NSArray alebo NSMutableArray.
    a potom spravit toto:

    cell.textLabel.text = [mojepole objectAtIndex:indexPath.row];

    alebo spravis pole NSDictionaries. cize:

    cell.textLabel.text = [[mojepole objectAtIndex:indexPath.row] objectForKey:nieco];

    alebo ak to chces objektovo tak si subclassnes UITableViewCell do vlastnej classy a tam si spravis properties.

    ale asi viem kde je problem.

    NSString *CellIdentifier = [NSString stringWithFormat:@“Cell%i“,indexPath.row];
    UITableViewCell *cell = (UITableViewCell*)[_tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    toto ti zabezpeci ze stale budes mat ten spravny text.

    #381591
    PATFFO
    Účastník (Participant)

    no ide o to že ako ja viem ako zobraziť časy aj to mam len problem je v tom že ked je rovnaky autobus na inych zastavkach tak su tie iste casy. proste na kazdu zastavku chcem ine casy pre ten isty autobus
    takto to mam

    – (void)viewDidLoad
    {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    UIBarButtonItem *NewBackButton = [[UIBarButtonItem alloc] initWithTitle:@““ style:UIBarButtonItemStyleBordered target:nil action:nil];
    [[self navigationItem] setBackBarButtonItem:NewBackButton];

    dvaOBR = [NSArray arrayWithObjects:@“17 40 30 20″, nil];
    }

    – (void)didReceiveMemoryWarning
    {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    }

    – (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
    // Return the number of sections.
    return 1;
    }

    – (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
    if ([_cas isEqualToString:@“4 – Sídlisko III“]) {
    return [dvaOBR count];
    }
    return 0;
    }

    – (TableViewCell_4 *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    static NSString *simpleTableIdentifier = @“TableViewCell_4″;

    TableViewCell_4 *cell = (TableViewCell_4 *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
    cell = [[TableViewCell_4 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }
    if ([_cas isEqualToString:@“4 – Sídlisko III“]) {
    cell.textLabel.text = [dvaOBR objectAtIndex:indexPath.row];
    }
    return cell;
    }

    #381592
    mayoxy
    Účastník (Participant)

    NSMutableDictionary *priklad = [NSMutableDictionary alloc] initWithObjectAndKeys:[NSArray …..],@“4 – Sidlisko III“,[NSArray ……],@“5 – Sidlisko IV“,nil];

    cell.textLabel.text = [[priklad objectForKey:@“4 – Sidlisko III“] objectAtIndex:indexPath.row]; —-> tu moze byt namiesto 4 – sidlisko III premenna nejaka. napriklad v akcii na kliknutie na button nejaky. Ze podla toho ktory autobus si vyberes, tak podla toho sa ti budu zobrazovat casy.

    to uz zalezi ako to mas naimplementovane, co kedy sa klika ,co kedy sa ma vykonat

    #381593
    PATFFO
    Účastník (Participant)

    ok mam pocit jak to myslíš.
    napisal som to tak
    NSMutableDictionary *Bajkalska = [NSMutableDictionary alloc] initWithObjectAndKeys:[NSArray *Bajkalská],@“4 – Sidlisko III“, [NSArray *Bajkalská],@“2 – Obr. Mieru“,nil];

    ale píše mi expected identifier

    #381596
    mayoxy
    Účastník (Participant)

    Objects and keys. pismeno s ti tam myslim chyba.
    ale co je [NSArray *Bajkalska] ? tak sa nedefinuje pole.

    #381597
    PATFFO
    Účastník (Participant)

    veď ja mam zrobene pole normalne co mi aj fungovalo vtedy NSArray *Bajkalská; tak som len doplnil do tej zatvorky. kedze to je podla teba zle ako to ma vyzerat?

Zobrazuje sa 7 príspevkov - 1 až 7 (z celkového počtu 7 )
  • Musíte byť prihlásený, aby ste mohli odpovedať na túto tému.