Night | Snow

iPhone Tutorial 1 (UITableView)

Posted on: February 7th, 2010

Tags:

In diesem ersten Tutorial geht es darum ein einfaches iPhone-App betehend aus einem UITableView zu erstellen. Es soll zeigen, wie ein Text in eine Zelle dieser Table-Übersicht geschrieben wird.

Wenn die iPhone SDK bereits installiert wurde, erscheint das folgende Fenseter mit den iPhone Projekt Templates. Wählen Sie das Erste “Navigation-Based Application” und geben Sie ein Projektname (Hier tutorial-1).

Wenn Sie unmittelbar nach dem Erstellen des Projekts auf “Build and Go” klicken erscheint eine leere Table-Übersicht. Als nächstes werden wir eine neue Zeile mit Text hinzufügen.

Dazu öffnen Sie die Datei RootViewController.m (Mehr zur Bedeutung der Standard Dateien finden Sie hier). Das ist der View-Controller, also hier der TableView der zur Hauptansicht (main view) hinzugefügt wird.

Suchen Sie die Funktion numberOfRowsInSection.

// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}

Hier wird die Anzahl der Zeilen festgelegt. Ändern Sie den Rückgabewert von 0 auf 1, um dem Programm mitzuteilen, dass wir eine Zeile haben wollen.

Als nächstes muss die Funktion cellForRowAtIndexPath angepasst werden. Diese Funktion wird für jede Zeile einmal aufgerufen. Hier kann auch der Zellentext gesetzt werden.

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}

// Set up the cell...
[cell setText:@"Hier kommt unser Text"];

return cell;
}

Der Funktion wurde nur der Aufruf der Methode setText der Zelle mit dem Parameter “Hier kommt unser Text” hinzugefügt. Dass “@” muss beim Objective-C vor jedem String stehen.
[cell setText:@"Hier kommt unser Text"];

Wenn Sie jetzt wieder auf “Build and Go” klicken erscheint der Text “Hier kommt unser Text” in der Zelle.

Posted in iphone | Trackback Url

News

  • Facebook shares see modest debut

    Facebook shares end a volatile first day of trading at $38.23, barely above the company's initial pricing, having initially jumped more than 10%.

  • Met Police to extract phone data

    Mobile phone data of suspects in police custody is to be extracted and retained, regardless of whether charges are brought, the BBC has learned.

  • Silicon trick for next-gen memory

    Researchers reveal details of a promising way to make a fundamentally different kind of computer memory chip.

Martin Fischer said:

Client and partner of simra.ch

Wir können Simon Schärer als kompetenter und zuverlässiger Programmierer höchst weiterempfehlen. Er ist nicht nur ein guter Programmierer, sondern auch ein ausgezeichneter Designer.
Danke Developer’s Island

Follow us on Twitter

favorite

I get asked a lot - which SDK should we use for web programming? I recommend Netbeans

my toolbar

Simra GameMP3 playersubscribe to RSSMy delicious bookmarksFacebookTwitterE-mail

No Responses to “iPhone Tutorial 1 (UITableView)”

RSS Feed Icon  Subscribe to comments follow-up

Trackbacks/Pingbacks

Leave a reply

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Latest Tweet

loading...