1

In my app I have ViewController, it placed TableView with Static cell. StoryBoard look likes this:

enter image description here

In .m file I wrote:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

[self.myTableView cellForRowAtIndexPath:indexPath];
    }

But I'm recieve an error: dataSource must return a cell from cellForRowAtIndexPath What I'm doing wrong?

daleijn
  • 718
  • 13
  • 22

1 Answers1

1

You are doing it wrong - inside that function you have to create and return a cell.

Most common implementation is:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

     static NSString *CellIdentifier = @"Cell";

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

    return cell;
}

From what I see you want to return different cells for different rows - than you have to create if/else block inside that function that will dequeue proper cell type with unique identifier per type.

It will be good if you at least go through one of tutorials. here is the one which should help you: http://www.appcoda.com/customize-table-view-cells-for-uitableview/

Grzegorz Krukowski
  • 18,081
  • 5
  • 50
  • 71
  • I just want TabeView looks like in Storyboard, and don't create something programmatically. I need only change labels.text properties – daleijn Dec 14 '13 at 11:11
  • You don't implement cellForRowAtIndexPath or any data source method in *static* table view, compare above "possible duplicate". – Martin R Dec 14 '13 at 18:01