
How to insert a table view inside view controller in Xcode?

in . h File
import <UIKit/UIKit.h> @interface TestTV : UITableView<UITableViewDataSource, UITableViewDelegate> @property(strong,nonatomic)NSArray *arr; @end
. M file
#import "TestTV.h"
@implementation TestTV
@synthesize arr = _arr;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
_arr = [[NSArray alloc]initWithObjects:@"HEJ",@"FOO", nil];
return _arr.count;
}
- (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];
}
NSString *cellValue = [_arr objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
return cell;
}
@end
set both the delegate and dataSource outlets of the table view to be equal to its superview's view controller
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.