Я пытаюсь создать UITableView
программно, но это заставляет меня запутать, поскольку реализован метод UITableViewDataSource
«с Протокол никогда не дозвонилисьUITableViewDataSource реализован метод не называется
ViewController
@interface viewController : UIViewController <UITableViewDataSource>
@end
#import "viewController.h"
@interface viewController()
@property (strong, nonatomic) NSArray *tweetsArray;
@end
@implementation viewController {
UITableView *tableView;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.tweetsArray = [[NSArray alloc] initWithObjects:
@"This is the first line",
@"This is the second line",
@"This is the third line",
@"This is the fourth line",
@"This is the fifth line",
nil];
tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
tableView.dataSource = self;
[self.view addSubview:tableView];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.tweetsArray count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"SettingsCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
NSString *tweet = [self.tweetsArray objectAtIndex:indexPath.row];
[cell.textLabel setText:@"Via Cuong Doan"];
[cell.detailTextLabel setText:tweet];
return cell;
}
@end
AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
viewController *view = [[viewController alloc] init];
[self.window addSubview:view.view];
return YES;
}
Все, кажется, прекрасно, но -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
и -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
никогда не дозвонились
ViewDidLoad называется? Я считаю, что не – Injectios
'viewDidLoad' вызывается, но два других не являются, поэтому меня путает –
' numberOfSecion' не установлен? – Larme