2012-04-12 16 views
2

我開始了一個標籤式應用程序項目,並在我的第一個觀點我想獲得一個填充的列表,所以我宣佈一個類似的NSArray如下:的TableView到tabBarController

@interface agrospineFirstViewController : UIViewController <UITableViewDelegate  ,UITableViewDataSource> 
{ 
NSArray *JournalList; 
} 
@property (nonatomic,retain) NSArray *JournalList; 
@end 

,我加上了.M如下:

[super viewDidLoad];

//initialisation de la liste 
JournalList = [NSArray arrayWithObjects:@"journal1",@"journal2",nil]; 


//initialisation du table View 
UITableView* tableView=[[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]style:UITableViewStylePlain]; 


//population de la vue 


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [JournalList count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *MyIdentifier = @"MyIdentifier"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 

if (cell == nil) 

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier]; 

// Configuration de la cellule 

NSString *cellValue = [JournalList objectAtIndex:indexPath.row]; 
cell.textLabel.text = cellValue; 
return cell; 

} 

我也DROP掉了tablelist到視圖...但仍表現出對numberOfRowsInSection錯誤,要求更換「:」通過「;」 任何幫助意見改善?

謝謝您的時間

+1

ü需要ALLOC您的陣列, JournalList = [[NSArray中的alloc] initWithObjects:@ 「journal1」,@ 「journal2」,零]。 – Charan 2012-04-12 09:45:17

+0

你應該粘貼視圖控制器的所有代碼。 – 2012-04-12 09:56:25

回答

2

我想你沒有關閉viewDidLoad中方法是這樣的:

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    //initialisation de la liste 
    JournalList = [NSArray arrayWithObjects:@"journal1",@"journal2",nil]; 


    //initialisation du table View 
    UITableView* tableView=[[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]style:UITableViewStylePlain]; 


    //population de la vue 
} 

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [JournalList count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *MyIdentifier = @"MyIdentifier"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 

    if (cell == nil) 

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier]; 

    // Configuration de la cellule 

    NSString *cellValue = [JournalList objectAtIndex:indexPath.row]; 
    cell.textLabel.text = cellValue; 
    return cell; 

} 
+0

它被關閉我沒有複製它 – Hosni 2012-04-12 09:50:38

+0

有你分配數組 – Charan 2012-04-12 09:51:50

+0

@SreeCharan數組初始化與此代碼:'JournalList = [NSArray arrayWithObjects:@「journal1」,@「journal2」,零];'但它應該被保留。 – 2012-04-12 09:54:47

2

你不需要這個
UITableView* tableView=[[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]style:UITableViewStylePlain];

只需添加表到ViewController並在這樣的appDelegate類中添加viewController名稱

UIViewController *homeViewController = [[[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil] autorelease]; 
self.tabBarController = [[[UITabBarController alloc] init] autorelease]; 
self.tabBarController.viewControllers = [NSArray arrayWithObjects:homeViewController,nil]; 

只要給在XIB類delagate和數據源連接

+0

我會問一個關於這個問題,我會給你發一個鏈接 – Hosni 2012-04-12 10:42:03

+0

我試着理解你在這裏寫了什麼,但我不認爲我明白了..你想說的是我應該添加一個視圖控制器數組到tabBarController? – Hosni 2012-04-12 11:11:00

+0

是的,你去吧。 – Charan 2012-04-12 11:52:41