Domov › Diskusné Fóra › Pomoc: software › Xcode – Rovnaky cell ale iny obsah
- Toto téma obsahuje 6 odpovedí, 2 hlasy, a bola naposledny upravená pred 11 years, 6 months od
PATFFO.
-
AutorPríspevky
-
19. apríla 2014 o 23:13 #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ť?
19. apríla 2014 o 23:30 #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.
20. apríla 2014 o 0:20 #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;
}20. apríla 2014 o 0:38 #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
20. apríla 2014 o 0:40 #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
20. apríla 2014 o 1:27 #381596
mayoxyÚčastník (Participant)Objects and keys. pismeno s ti tam myslim chyba.
ale co je [NSArray *Bajkalska] ? tak sa nedefinuje pole.20. apríla 2014 o 1:33 #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?
-
AutorPríspevky
- Musíte byť prihlásený, aby ste mohli odpovedať na túto tému.