2011-11-16 33 views
1

我正在做一个基于导航的应用程序,在那里我有一个名为DataService.m文件和我的RootViewController的的NSArray和实现代码如下

.M

在我DataService.m我打电话

-(NSArray*)loadData 
{ 
    AlarmItem *item1 = [[[AlarmItem alloc] initWithTitle:@"TEST2"] autorelease]; 
    AlarmItem *item2 = [[[AlarmItem alloc] initWithTitle:@"TEST3"] autorelease]; 
    AlarmItem *item3 = [[[AlarmItem alloc] initWithTitle:@"TEST4"] autorelease]; 
    AlarmItem *item4 = [[[AlarmItem alloc] initWithTitle:@"TEST5"] autorelease]; 
    AlarmItem *item5 = [[[AlarmItem alloc] initWithTitle:@"TEST6"] autorelease]; 

    NSMutableArray *items = [NSMutableArray arrayWithObjects:item1, item2, item3, item4, item5, NULL]; 

    return items; 
} 

,并在我的RootViewCoontroller.mi有

- (IBAction)RefreshAlarmList:(id)sender 
{ 
    XMLDataService *myXML = [[XMLDataService alloc] init]; 
    [myXML loadData]; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh 
    target:self action:@selector(RefreshAlarmList:)]; 
    self.navigationItem.rightBarButtonItem = refreshButton; 
    [refreshButton release]; 
} 

当我跑我的模拟器的tableView被空......我如何显示我的物品?

+0

有很多关于表视图教程去通过再拿出与问题。 – iamsult

+0

我已经尝试了很多窍门,但我找不到答案。 – user993074

+0

你在哪里告诉你的tableview要加载什么(即rowsPerSection,tableView:cellForRowAtIndexPath :)?你跟着哪些教程没有帮助? – deanWombourne

回答

0

不要autorelease函数加载到tableview然后autorelease it.Then你怎么显示数据到tableview.give行动作为重新加载tableview中的数据。

+0

我应该在dealloc中释放item1等吗? – user993074

+0

我试图做到这一点,但它仍然dosent在表中显示任何 – user993074

+0

没关系,你是如何将细节到细胞 – Marios

0

你可以尝试一件事情。在委托方法cellForRowAtIndexPath中,在上次你应该返回cell.It可能工作。

  • (的UITableViewCell *)的tableView:(UITableView的*)的tableView的cellForRowAtIndexPath:(NSIndexPath *)indexPath {静态的NSString * CellIdentifier = @ “小区”; UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];如果(cell == nil){cell = [[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; } //配置单元格。 AlarmItem * item = [_items objectAtIndex:indexPath.row]; cell.textLabel.text = item.tagName;返回细胞;}
0
[myXML loadData]; 

这是返回一个数组,这大概将要作为表的数据源使用,但你用它做什么。您需要将此分配给数组,这是你的视图控制器类,_itemsitems一个保留伊娃您的其他意见判断:

self.items = [myXML loadData];