2012-04-12 51 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