[英]NSArray and tableview
I'm making a navigation-based application, where i have a file called DataService.m and my RootViewController 我正在制作一个基于导航的应用程序,其中有一个名为DataService.m的文件和我的RootViewController
.m .m
in my DataService.m I'm calling 在我的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;
}
and in my RootViewCoontroller.mi have 在我的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];
}
When I run my simulator the tableView is empty.. how can i display my items ? 当我运行模拟器时,tableView为空。如何显示项目?
加载到表视图中后不要autorelease
该函数,然后自动释放它,然后您如何将数据显示到表视图中。作为在表视图中重新加载数据的操作。
You can try one thing.Here in the delegate method cellForRowAtIndexPath , in last u should return the cell.It may work. 您可以尝试一件事,在委托方法cellForRowAtIndexPath中,最后您应该返回该单元格。
[myXML loadData];
This is returning an array, which presumably you wish to use as your table's data source, but you are doing nothing with it. 这将返回一个数组,可能您希望将其用作表的数据源,但您对此无所事事。 You need to assign this to an array, which is a retained ivar in your view controller class,
_items
or items
judging by your other comments: 您需要将此分配给一个数组,该数组是视图控制器类,
_items
或通过其他注释判断的items
保留的ivar:
self.items = [myXML loadData];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.