I have got an UITableView. How to simply fill it with three elements, for example "e1", "e2", "e3" ?
+3
A:
set DataSource of your table to your class and define in your class 3 methods:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section {
return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellId = @"identifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: cellId];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellId] autorelease];
}
[cell setText:[NSString stringWithFormat:@"e%i",indexPath:[indexPath row]];
return cell;
}
Igor
2009-01-25 00:02:29
A:
UITableView is a component that rewards study. Read the local doc pages on UITableView and its datasource and delegate protocols. There is a table view programming guide in the docs as well. It is a good read. Some of it took me a while to grok and I am still refining my approach each time I implement one. Using the API and implementing the methods it requires, you should be able to bend it to your will.
Hellra1ser's example should push you in the right direction. Lookup those methods first, you will be using them alot.
Ryan Townshend
2009-01-25 03:18:25