2014-01-08 82 views
0

在我的應用程序中我正在使用故事板。在故事板中,我使用默認視圖控制器進行登錄,並創建了另一個視圖控制器名稱庫存。在新的視圖控制器我使用表視圖。該表正在顯示,但委託和數據源方法未被調用。我已經嘗試了許多解決方案,但我明白憑着我所用的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 
+0

在運行中實現的動畫塊項目? – Ashutosh

+0

@Ashu沒有你好,沒有打印和沒有的單元格也不是10 .. – BalaChandra

回答

1

您需要申請 - reloadData:方法設置deledate後,數據源和數據源數組。

reloadData

重新加載接收者的行和部分。 - (void)reloadData 討論

調用此方法重新加載用於構造表的所有數據,包括單元格,節標題和頁腳,索引數組等等。爲了提高效率,表格視圖僅重新顯示那些可見的行。如果表格由於重新加載而縮小,它會調整偏移量。表視圖的委託或數據源在希望表視圖完全重新加載其數據時調用此方法。它不應該在插入或刪除行的方法被調用,特別是在與調用beginUpdates和endUpdates

通過這個文檔是「你好」印在日誌中https://developer.apple.com/library/ios/documentation/uikit/reference/UITableView_Class/Reference/Reference.html#//apple_ref/occ/instm/UITableView/reloadData

+0

我已經添加了該方法,仍然沒有調用委託方法,並且空的表格正在來臨 – BalaChandra

+0

@BalaChandra,更新您的問題最新代碼並檢查自定義單元插座是否正確配置/如果以編程方式檢查代碼。 – Tirth

+0

Customecell被配置,但即使我已經指定的單元格數爲10,並在該方法我已經使用nsLog(@「你好」)它也不是打印的單元格號不是10 – BalaChandra

相關問題