iOS UI -- Custom UI with Embeded Table View Cell
In an .xid file, you can not define a custom Table View Cell in the Table View. (Although you can do it in storyboard).
If you want to do so, you have to create the Table View Cell by codes.
In a .xib file, if you want to embeded a Table View Cell inside the Tabel View, your latest Xcode, might be Version 6.4 would not allow you to do so before compiling.
However in the previous versions, you can do
that but you will encounter a compiling error. Somewhat similar to you can not put a placeholder inside an .xib file.
Not like in a storyboard, you can define the custom table view cell as a placeholder directly.
Fortunatelly, you can always do that programmly.
Step 1. Define you own table view cell in another .xib file
Step 2. Define your custom view in .xib file
Just do what you had planned to do, except including the Table View Cell inside Table View.
Step 3. Put your custom Table View Cell as subviews inside Table View by coding
In the class of your custom view, creating those rows by coding.
For example, I implement the interface of <UITableViewDelegate, ChartViewDelegate>
of the class of my custom UIView
@class CustomView;
@interface CustomView : UIView <UITableViewDataSource, UITableViewDelegate>
@end
And You can create each row with the sytle of your predefined custom table view cell in the cellForRowAtIndexPath
method of UITableViewDataSource
interface.
@implementation CustomView
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"myCell";
MyCustomCell *cell = (MyCustomCell *)
[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = (MyCustomCell *)[[[NSBundle mainBundle]
loadNibNamed:@"MyCustomCell" owner:self options:nil] lastObject];
}
...
return cell;
}
@end
Reference
-
Creating Custom UITableViewCell using Nib (.xib) files in XCode This guide you how to define your own Table View Cell and then you can add it to the table view programmically.