在我的應用程序中我正在使用故事板。在故事板中,我使用默認視圖控制器進行登錄,並創建了另一個視圖控制器名稱庫存。在新的視圖控制器我使用表視圖。該表正在顯示,但委託和數據源方法未被調用。我已經嘗試了許多解決方案,但我明白憑着我所用的problem.The代碼:表視圖委託方法不在故事板中的新視圖控制器中調用
#import <UIKit/UIKit.h>
@interface InventoryViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
@end
實現文件是:
#import "InventoryViewController.h"
#import "customCell.h"
@interface InventoryViewController()
@end
@implementation InventoryViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor blueColor];
UITableView *table = [[UITableView alloc] initWithFrame:CGRectMake(0, 110, 320, 350)];
table.delegate = self;
table.dataSource = self;
[self.view addSubview:table];
[table relaodData];
}
- (IBAction)Logout:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"Login"];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - UITableViewDelegate Methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1; }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"hello");
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
customCell *cell = [tableView dequeueReusableCellWithIdentifier:@"customcell"];
if (cell == nil)
{
cell = [[customCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"customcell"];
}
// Here we use the provided setImageWithURL: method to load the web image
// Ensure you use a placeholder image otherwise cells will be initialized with no image
cell.item_image.image = [UIImage imageNamed:@"ipad_strip_logo.png"];
cell.type.text = @"electronics";
cell.name.text = [NSString stringWithFormat:@"my object %d",indexPath.row];
return cell;
}
@end
在運行中實現的動畫塊項目? – Ashutosh
@Ashu沒有你好,沒有打印和沒有的單元格也不是10 .. – BalaChandra