Reputation: 28907
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:
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.
Here is a demonstration that I have set the tag of the UIView to 1.
And here is the UITableView:
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
Reputation: 10615
I think you need to drag and drop UITableViewCell
to your UITableView
not UIView
.
Here is the screenshot:
Upvotes: 1