如何简单地为iPhone填充TableView

3 cocoa-touch

我有一个UITableView.如何简单地用三个元素填充它,例如"e1","e2","e3"?

Igo*_*gor 7

将表的DataSource设置为您的类并在您的类3中定义方法:

- (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;
}
Run Code Online (Sandbox Code Playgroud)