CodeGuy
CodeGuy

Reputation: 28907

iOS Storyboard - creating customized UITableViewCell

I'm trying to create a custom UITableViewCell via Storyboard for my iPhone App (Note: this is iOS 7).

Each cell is a bit complicated, consisting of a UIView with a few labels. In other words, I want to set up a prototype cell by customizing the content view of the cell itself.

Here are the steps I tried:

  1. Drag a UIView into the Table View in Storyboard and set it's tag to be 1.
  2. Added a single label to that UIView (ultimately, I will need several labels).
  3. Implemented some basic table view methods:

As follows:

-(int)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}

- (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];
    }

    UIView *view = (UIView *)[cell viewWithTag:1];
    NSLog(@"%@",view); //this just prints "(null)" a bunch of times

    return cell;
}

Here's the hierarchy of my GUI elements.

enter image description here

Here is a demonstration that I have set the tag of the UIView to 1.

enter image description here

And here is the UITableView:

enter image description here

It prints out (null) many times. What is the proper way to do this? I haven't had success finding any tutorials for complex custom UITableViewCells that are built through storyboard.

Upvotes: 1

Views: 294

Answers (1)

Yas Tabasam
Yas Tabasam

Reputation: 10615

I think you need to drag and drop UITableViewCell to your UITableView not UIView.

Here is the screenshot:

enter image description here

Upvotes: 1

Related Questions